/src/cpython/Modules/clinic/_threadmodule.c.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
6 | | # include "pycore_gc.h" // PyGC_Head |
7 | | # include "pycore_runtime.h" // _Py_ID() |
8 | | #endif |
9 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
10 | | |
11 | | PyDoc_STRVAR(_thread_lock_acquire__doc__, |
12 | | "acquire($self, /, blocking=True, timeout=-1)\n" |
13 | | "--\n" |
14 | | "\n" |
15 | | "Lock the lock.\n" |
16 | | "\n" |
17 | | "Without argument, this blocks if the lock is already\n" |
18 | | "locked (even by the same thread), waiting for another thread to release\n" |
19 | | "the lock, and return True once the lock is acquired.\n" |
20 | | "With an argument, this will only block if the argument is true,\n" |
21 | | "and the return value reflects whether the lock is acquired.\n" |
22 | | "The blocking operation is interruptible."); |
23 | | |
24 | | #define _THREAD_LOCK_ACQUIRE_METHODDEF \ |
25 | | {"acquire", _PyCFunction_CAST(_thread_lock_acquire), METH_FASTCALL|METH_KEYWORDS, _thread_lock_acquire__doc__}, |
26 | | |
27 | | static PyObject * |
28 | | _thread_lock_acquire_impl(lockobject *self, int blocking, |
29 | | PyObject *timeoutobj); |
30 | | |
31 | | static PyObject * |
32 | | _thread_lock_acquire(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
33 | 0 | { |
34 | 0 | PyObject *return_value = NULL; |
35 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
36 | |
|
37 | 0 | #define NUM_KEYWORDS 2 |
38 | 0 | static struct { |
39 | 0 | PyGC_Head _this_is_not_used; |
40 | 0 | PyObject_VAR_HEAD |
41 | 0 | Py_hash_t ob_hash; |
42 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
43 | 0 | } _kwtuple = { |
44 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
45 | 0 | .ob_hash = -1, |
46 | 0 | .ob_item = { &_Py_ID(blocking), &_Py_ID(timeout), }, |
47 | 0 | }; |
48 | 0 | #undef NUM_KEYWORDS |
49 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
50 | |
|
51 | | #else // !Py_BUILD_CORE |
52 | | # define KWTUPLE NULL |
53 | | #endif // !Py_BUILD_CORE |
54 | |
|
55 | 0 | static const char * const _keywords[] = {"blocking", "timeout", NULL}; |
56 | 0 | static _PyArg_Parser _parser = { |
57 | 0 | .keywords = _keywords, |
58 | 0 | .fname = "acquire", |
59 | 0 | .kwtuple = KWTUPLE, |
60 | 0 | }; |
61 | 0 | #undef KWTUPLE |
62 | 0 | PyObject *argsbuf[2]; |
63 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
64 | 0 | int blocking = 1; |
65 | 0 | PyObject *timeoutobj = NULL; |
66 | |
|
67 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
68 | 0 | /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
69 | 0 | if (!args) { |
70 | 0 | goto exit; |
71 | 0 | } |
72 | 0 | if (!noptargs) { |
73 | 0 | goto skip_optional_pos; |
74 | 0 | } |
75 | 0 | if (args[0]) { |
76 | 0 | blocking = PyObject_IsTrue(args[0]); |
77 | 0 | if (blocking < 0) { |
78 | 0 | goto exit; |
79 | 0 | } |
80 | 0 | if (!--noptargs) { |
81 | 0 | goto skip_optional_pos; |
82 | 0 | } |
83 | 0 | } |
84 | 0 | timeoutobj = args[1]; |
85 | 0 | skip_optional_pos: |
86 | 0 | return_value = _thread_lock_acquire_impl((lockobject *)self, blocking, timeoutobj); |
87 | |
|
88 | 0 | exit: |
89 | 0 | return return_value; |
90 | 0 | } |
91 | | |
92 | | PyDoc_STRVAR(_thread_lock_acquire_lock__doc__, |
93 | | "acquire_lock($self, /, blocking=True, timeout=-1)\n" |
94 | | "--\n" |
95 | | "\n" |
96 | | "An obsolete synonym of acquire()."); |
97 | | |
98 | | #define _THREAD_LOCK_ACQUIRE_LOCK_METHODDEF \ |
99 | | {"acquire_lock", _PyCFunction_CAST(_thread_lock_acquire_lock), METH_FASTCALL|METH_KEYWORDS, _thread_lock_acquire_lock__doc__}, |
100 | | |
101 | | static PyObject * |
102 | | _thread_lock_acquire_lock_impl(lockobject *self, int blocking, |
103 | | PyObject *timeoutobj); |
104 | | |
105 | | static PyObject * |
106 | | _thread_lock_acquire_lock(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
107 | 0 | { |
108 | 0 | PyObject *return_value = NULL; |
109 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
110 | |
|
111 | 0 | #define NUM_KEYWORDS 2 |
112 | 0 | static struct { |
113 | 0 | PyGC_Head _this_is_not_used; |
114 | 0 | PyObject_VAR_HEAD |
115 | 0 | Py_hash_t ob_hash; |
116 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
117 | 0 | } _kwtuple = { |
118 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
119 | 0 | .ob_hash = -1, |
120 | 0 | .ob_item = { &_Py_ID(blocking), &_Py_ID(timeout), }, |
121 | 0 | }; |
122 | 0 | #undef NUM_KEYWORDS |
123 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
124 | |
|
125 | | #else // !Py_BUILD_CORE |
126 | | # define KWTUPLE NULL |
127 | | #endif // !Py_BUILD_CORE |
128 | |
|
129 | 0 | static const char * const _keywords[] = {"blocking", "timeout", NULL}; |
130 | 0 | static _PyArg_Parser _parser = { |
131 | 0 | .keywords = _keywords, |
132 | 0 | .fname = "acquire_lock", |
133 | 0 | .kwtuple = KWTUPLE, |
134 | 0 | }; |
135 | 0 | #undef KWTUPLE |
136 | 0 | PyObject *argsbuf[2]; |
137 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
138 | 0 | int blocking = 1; |
139 | 0 | PyObject *timeoutobj = NULL; |
140 | |
|
141 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
142 | 0 | /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
143 | 0 | if (!args) { |
144 | 0 | goto exit; |
145 | 0 | } |
146 | 0 | if (!noptargs) { |
147 | 0 | goto skip_optional_pos; |
148 | 0 | } |
149 | 0 | if (args[0]) { |
150 | 0 | blocking = PyObject_IsTrue(args[0]); |
151 | 0 | if (blocking < 0) { |
152 | 0 | goto exit; |
153 | 0 | } |
154 | 0 | if (!--noptargs) { |
155 | 0 | goto skip_optional_pos; |
156 | 0 | } |
157 | 0 | } |
158 | 0 | timeoutobj = args[1]; |
159 | 0 | skip_optional_pos: |
160 | 0 | return_value = _thread_lock_acquire_lock_impl((lockobject *)self, blocking, timeoutobj); |
161 | |
|
162 | 0 | exit: |
163 | 0 | return return_value; |
164 | 0 | } |
165 | | |
166 | | PyDoc_STRVAR(_thread_lock_release__doc__, |
167 | | "release($self, /)\n" |
168 | | "--\n" |
169 | | "\n" |
170 | | "Release the lock.\n" |
171 | | "\n" |
172 | | "Allows another thread that is blocked waiting for\n" |
173 | | "the lock to acquire the lock. The lock must be in the locked state,\n" |
174 | | "but it needn\'t be locked by the same thread that unlocks it."); |
175 | | |
176 | | #define _THREAD_LOCK_RELEASE_METHODDEF \ |
177 | | {"release", (PyCFunction)_thread_lock_release, METH_NOARGS, _thread_lock_release__doc__}, |
178 | | |
179 | | static PyObject * |
180 | | _thread_lock_release_impl(lockobject *self); |
181 | | |
182 | | static PyObject * |
183 | | _thread_lock_release(PyObject *self, PyObject *Py_UNUSED(ignored)) |
184 | 0 | { |
185 | 0 | return _thread_lock_release_impl((lockobject *)self); |
186 | 0 | } |
187 | | |
188 | | PyDoc_STRVAR(_thread_lock_release_lock__doc__, |
189 | | "release_lock($self, /)\n" |
190 | | "--\n" |
191 | | "\n" |
192 | | "An obsolete synonym of release()."); |
193 | | |
194 | | #define _THREAD_LOCK_RELEASE_LOCK_METHODDEF \ |
195 | | {"release_lock", (PyCFunction)_thread_lock_release_lock, METH_NOARGS, _thread_lock_release_lock__doc__}, |
196 | | |
197 | | static PyObject * |
198 | | _thread_lock_release_lock_impl(lockobject *self); |
199 | | |
200 | | static PyObject * |
201 | | _thread_lock_release_lock(PyObject *self, PyObject *Py_UNUSED(ignored)) |
202 | 0 | { |
203 | 0 | return _thread_lock_release_lock_impl((lockobject *)self); |
204 | 0 | } |
205 | | |
206 | | PyDoc_STRVAR(_thread_lock___enter____doc__, |
207 | | "__enter__($self, /)\n" |
208 | | "--\n" |
209 | | "\n" |
210 | | "Lock the lock."); |
211 | | |
212 | | #define _THREAD_LOCK___ENTER___METHODDEF \ |
213 | | {"__enter__", (PyCFunction)_thread_lock___enter__, METH_NOARGS, _thread_lock___enter____doc__}, |
214 | | |
215 | | static PyObject * |
216 | | _thread_lock___enter___impl(lockobject *self); |
217 | | |
218 | | static PyObject * |
219 | | _thread_lock___enter__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
220 | 0 | { |
221 | 0 | return _thread_lock___enter___impl((lockobject *)self); |
222 | 0 | } |
223 | | |
224 | | PyDoc_STRVAR(_thread_lock___exit____doc__, |
225 | | "__exit__($self, exc_type, exc_value, exc_tb, /)\n" |
226 | | "--\n" |
227 | | "\n" |
228 | | "Release the lock."); |
229 | | |
230 | | #define _THREAD_LOCK___EXIT___METHODDEF \ |
231 | | {"__exit__", _PyCFunction_CAST(_thread_lock___exit__), METH_FASTCALL, _thread_lock___exit____doc__}, |
232 | | |
233 | | static PyObject * |
234 | | _thread_lock___exit___impl(lockobject *self, PyObject *exc_type, |
235 | | PyObject *exc_value, PyObject *exc_tb); |
236 | | |
237 | | static PyObject * |
238 | | _thread_lock___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
239 | 0 | { |
240 | 0 | PyObject *return_value = NULL; |
241 | 0 | PyObject *exc_type; |
242 | 0 | PyObject *exc_value; |
243 | 0 | PyObject *exc_tb; |
244 | |
|
245 | 0 | if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) { |
246 | 0 | goto exit; |
247 | 0 | } |
248 | 0 | exc_type = args[0]; |
249 | 0 | exc_value = args[1]; |
250 | 0 | exc_tb = args[2]; |
251 | 0 | return_value = _thread_lock___exit___impl((lockobject *)self, exc_type, exc_value, exc_tb); |
252 | |
|
253 | 0 | exit: |
254 | 0 | return return_value; |
255 | 0 | } |
256 | | |
257 | | PyDoc_STRVAR(_thread_lock_locked__doc__, |
258 | | "locked($self, /)\n" |
259 | | "--\n" |
260 | | "\n" |
261 | | "Return whether the lock is in the locked state."); |
262 | | |
263 | | #define _THREAD_LOCK_LOCKED_METHODDEF \ |
264 | | {"locked", (PyCFunction)_thread_lock_locked, METH_NOARGS, _thread_lock_locked__doc__}, |
265 | | |
266 | | static PyObject * |
267 | | _thread_lock_locked_impl(lockobject *self); |
268 | | |
269 | | static PyObject * |
270 | | _thread_lock_locked(PyObject *self, PyObject *Py_UNUSED(ignored)) |
271 | 0 | { |
272 | 0 | return _thread_lock_locked_impl((lockobject *)self); |
273 | 0 | } |
274 | | |
275 | | PyDoc_STRVAR(_thread_lock_locked_lock__doc__, |
276 | | "locked_lock($self, /)\n" |
277 | | "--\n" |
278 | | "\n" |
279 | | "An obsolete synonym of locked()."); |
280 | | |
281 | | #define _THREAD_LOCK_LOCKED_LOCK_METHODDEF \ |
282 | | {"locked_lock", (PyCFunction)_thread_lock_locked_lock, METH_NOARGS, _thread_lock_locked_lock__doc__}, |
283 | | |
284 | | static PyObject * |
285 | | _thread_lock_locked_lock_impl(lockobject *self); |
286 | | |
287 | | static PyObject * |
288 | | _thread_lock_locked_lock(PyObject *self, PyObject *Py_UNUSED(ignored)) |
289 | 0 | { |
290 | 0 | return _thread_lock_locked_lock_impl((lockobject *)self); |
291 | 0 | } |
292 | | |
293 | | #if defined(HAVE_FORK) |
294 | | |
295 | | PyDoc_STRVAR(_thread_lock__at_fork_reinit__doc__, |
296 | | "_at_fork_reinit($self, /)\n" |
297 | | "--\n" |
298 | | "\n"); |
299 | | |
300 | | #define _THREAD_LOCK__AT_FORK_REINIT_METHODDEF \ |
301 | | {"_at_fork_reinit", (PyCFunction)_thread_lock__at_fork_reinit, METH_NOARGS, _thread_lock__at_fork_reinit__doc__}, |
302 | | |
303 | | static PyObject * |
304 | | _thread_lock__at_fork_reinit_impl(lockobject *self); |
305 | | |
306 | | static PyObject * |
307 | | _thread_lock__at_fork_reinit(PyObject *self, PyObject *Py_UNUSED(ignored)) |
308 | 0 | { |
309 | 0 | return _thread_lock__at_fork_reinit_impl((lockobject *)self); |
310 | 0 | } |
311 | | |
312 | | #endif /* defined(HAVE_FORK) */ |
313 | | |
314 | | static PyObject * |
315 | | lock_new_impl(PyTypeObject *type); |
316 | | |
317 | | static PyObject * |
318 | | lock_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
319 | 0 | { |
320 | 0 | PyObject *return_value = NULL; |
321 | 0 | PyTypeObject *base_tp = clinic_state()->lock_type; |
322 | |
|
323 | 0 | if ((type == base_tp || type->tp_init == base_tp->tp_init) && |
324 | 0 | !_PyArg_NoPositional("lock", args)) { |
325 | 0 | goto exit; |
326 | 0 | } |
327 | 0 | if ((type == base_tp || type->tp_init == base_tp->tp_init) && |
328 | 0 | !_PyArg_NoKeywords("lock", kwargs)) { |
329 | 0 | goto exit; |
330 | 0 | } |
331 | 0 | return_value = lock_new_impl(type); |
332 | |
|
333 | 0 | exit: |
334 | 0 | return return_value; |
335 | 0 | } |
336 | | |
337 | | PyDoc_STRVAR(_thread_RLock_acquire__doc__, |
338 | | "acquire($self, /, blocking=True, timeout=-1)\n" |
339 | | "--\n" |
340 | | "\n" |
341 | | "Lock the lock.\n" |
342 | | "\n" |
343 | | "`blocking` indicates whether we should wait\n" |
344 | | "for the lock to be available or not. If `blocking` is False\n" |
345 | | "and another thread holds the lock, the method will return False\n" |
346 | | "immediately. If `blocking` is True and another thread holds\n" |
347 | | "the lock, the method will wait for the lock to be released,\n" |
348 | | "take it and then return True.\n" |
349 | | "(note: the blocking operation is interruptible.)\n" |
350 | | "\n" |
351 | | "In all other cases, the method will return True immediately.\n" |
352 | | "Precisely, if the current thread already holds the lock, its\n" |
353 | | "internal counter is simply incremented. If nobody holds the lock,\n" |
354 | | "the lock is taken and its internal counter initialized to 1."); |
355 | | |
356 | | #define _THREAD_RLOCK_ACQUIRE_METHODDEF \ |
357 | | {"acquire", _PyCFunction_CAST(_thread_RLock_acquire), METH_FASTCALL|METH_KEYWORDS, _thread_RLock_acquire__doc__}, |
358 | | |
359 | | static PyObject * |
360 | | _thread_RLock_acquire_impl(rlockobject *self, int blocking, |
361 | | PyObject *timeoutobj); |
362 | | |
363 | | static PyObject * |
364 | | _thread_RLock_acquire(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
365 | 0 | { |
366 | 0 | PyObject *return_value = NULL; |
367 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
368 | |
|
369 | 0 | #define NUM_KEYWORDS 2 |
370 | 0 | static struct { |
371 | 0 | PyGC_Head _this_is_not_used; |
372 | 0 | PyObject_VAR_HEAD |
373 | 0 | Py_hash_t ob_hash; |
374 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
375 | 0 | } _kwtuple = { |
376 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
377 | 0 | .ob_hash = -1, |
378 | 0 | .ob_item = { &_Py_ID(blocking), &_Py_ID(timeout), }, |
379 | 0 | }; |
380 | 0 | #undef NUM_KEYWORDS |
381 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
382 | |
|
383 | | #else // !Py_BUILD_CORE |
384 | | # define KWTUPLE NULL |
385 | | #endif // !Py_BUILD_CORE |
386 | |
|
387 | 0 | static const char * const _keywords[] = {"blocking", "timeout", NULL}; |
388 | 0 | static _PyArg_Parser _parser = { |
389 | 0 | .keywords = _keywords, |
390 | 0 | .fname = "acquire", |
391 | 0 | .kwtuple = KWTUPLE, |
392 | 0 | }; |
393 | 0 | #undef KWTUPLE |
394 | 0 | PyObject *argsbuf[2]; |
395 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
396 | 0 | int blocking = 1; |
397 | 0 | PyObject *timeoutobj = NULL; |
398 | |
|
399 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
400 | 0 | /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
401 | 0 | if (!args) { |
402 | 0 | goto exit; |
403 | 0 | } |
404 | 0 | if (!noptargs) { |
405 | 0 | goto skip_optional_pos; |
406 | 0 | } |
407 | 0 | if (args[0]) { |
408 | 0 | blocking = PyObject_IsTrue(args[0]); |
409 | 0 | if (blocking < 0) { |
410 | 0 | goto exit; |
411 | 0 | } |
412 | 0 | if (!--noptargs) { |
413 | 0 | goto skip_optional_pos; |
414 | 0 | } |
415 | 0 | } |
416 | 0 | timeoutobj = args[1]; |
417 | 0 | skip_optional_pos: |
418 | 0 | return_value = _thread_RLock_acquire_impl((rlockobject *)self, blocking, timeoutobj); |
419 | |
|
420 | 0 | exit: |
421 | 0 | return return_value; |
422 | 0 | } |
423 | | |
424 | | PyDoc_STRVAR(_thread_RLock___enter____doc__, |
425 | | "__enter__($self, /)\n" |
426 | | "--\n" |
427 | | "\n" |
428 | | "Lock the lock."); |
429 | | |
430 | | #define _THREAD_RLOCK___ENTER___METHODDEF \ |
431 | | {"__enter__", (PyCFunction)_thread_RLock___enter__, METH_NOARGS, _thread_RLock___enter____doc__}, |
432 | | |
433 | | static PyObject * |
434 | | _thread_RLock___enter___impl(rlockobject *self); |
435 | | |
436 | | static PyObject * |
437 | | _thread_RLock___enter__(PyObject *self, PyObject *Py_UNUSED(ignored)) |
438 | 5.69k | { |
439 | 5.69k | return _thread_RLock___enter___impl((rlockobject *)self); |
440 | 5.69k | } |
441 | | |
442 | | PyDoc_STRVAR(_thread_RLock_release__doc__, |
443 | | "release($self, /)\n" |
444 | | "--\n" |
445 | | "\n" |
446 | | "Release the lock.\n" |
447 | | "\n" |
448 | | "Allows another thread that is blocked waiting for\n" |
449 | | "the lock to acquire the lock. The lock must be in the locked state,\n" |
450 | | "and must be locked by the same thread that unlocks it; otherwise a\n" |
451 | | "`RuntimeError` is raised.\n" |
452 | | "\n" |
453 | | "Do note that if the lock was acquire()d several times in a row by the\n" |
454 | | "current thread, release() needs to be called as many times for the lock\n" |
455 | | "to be available for other threads."); |
456 | | |
457 | | #define _THREAD_RLOCK_RELEASE_METHODDEF \ |
458 | | {"release", (PyCFunction)_thread_RLock_release, METH_NOARGS, _thread_RLock_release__doc__}, |
459 | | |
460 | | static PyObject * |
461 | | _thread_RLock_release_impl(rlockobject *self); |
462 | | |
463 | | static PyObject * |
464 | | _thread_RLock_release(PyObject *self, PyObject *Py_UNUSED(ignored)) |
465 | 0 | { |
466 | 0 | return _thread_RLock_release_impl((rlockobject *)self); |
467 | 0 | } |
468 | | |
469 | | PyDoc_STRVAR(_thread_RLock___exit____doc__, |
470 | | "__exit__($self, exc_type, exc_value, exc_tb, /)\n" |
471 | | "--\n" |
472 | | "\n" |
473 | | "Release the lock."); |
474 | | |
475 | | #define _THREAD_RLOCK___EXIT___METHODDEF \ |
476 | | {"__exit__", _PyCFunction_CAST(_thread_RLock___exit__), METH_FASTCALL, _thread_RLock___exit____doc__}, |
477 | | |
478 | | static PyObject * |
479 | | _thread_RLock___exit___impl(rlockobject *self, PyObject *exc_type, |
480 | | PyObject *exc_value, PyObject *exc_tb); |
481 | | |
482 | | static PyObject * |
483 | | _thread_RLock___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
484 | 5.69k | { |
485 | 5.69k | PyObject *return_value = NULL; |
486 | 5.69k | PyObject *exc_type; |
487 | 5.69k | PyObject *exc_value; |
488 | 5.69k | PyObject *exc_tb; |
489 | | |
490 | 5.69k | if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) { |
491 | 0 | goto exit; |
492 | 0 | } |
493 | 5.69k | exc_type = args[0]; |
494 | 5.69k | exc_value = args[1]; |
495 | 5.69k | exc_tb = args[2]; |
496 | 5.69k | return_value = _thread_RLock___exit___impl((rlockobject *)self, exc_type, exc_value, exc_tb); |
497 | | |
498 | 5.69k | exit: |
499 | 5.69k | return return_value; |
500 | 5.69k | } |
501 | | |
502 | | PyDoc_STRVAR(_thread_RLock_locked__doc__, |
503 | | "locked($self, /)\n" |
504 | | "--\n" |
505 | | "\n" |
506 | | "Return a boolean indicating whether this object is locked right now."); |
507 | | |
508 | | #define _THREAD_RLOCK_LOCKED_METHODDEF \ |
509 | | {"locked", (PyCFunction)_thread_RLock_locked, METH_NOARGS, _thread_RLock_locked__doc__}, |
510 | | |
511 | | static PyObject * |
512 | | _thread_RLock_locked_impl(rlockobject *self); |
513 | | |
514 | | static PyObject * |
515 | | _thread_RLock_locked(PyObject *self, PyObject *Py_UNUSED(ignored)) |
516 | 0 | { |
517 | 0 | return _thread_RLock_locked_impl((rlockobject *)self); |
518 | 0 | } |
519 | | |
520 | | PyDoc_STRVAR(_thread_RLock__acquire_restore__doc__, |
521 | | "_acquire_restore($self, state, /)\n" |
522 | | "--\n" |
523 | | "\n" |
524 | | "For internal use by `threading.Condition`."); |
525 | | |
526 | | #define _THREAD_RLOCK__ACQUIRE_RESTORE_METHODDEF \ |
527 | | {"_acquire_restore", (PyCFunction)_thread_RLock__acquire_restore, METH_O, _thread_RLock__acquire_restore__doc__}, |
528 | | |
529 | | static PyObject * |
530 | | _thread_RLock__acquire_restore_impl(rlockobject *self, PyObject *state); |
531 | | |
532 | | static PyObject * |
533 | | _thread_RLock__acquire_restore(PyObject *self, PyObject *state) |
534 | 0 | { |
535 | 0 | PyObject *return_value = NULL; |
536 | |
|
537 | 0 | return_value = _thread_RLock__acquire_restore_impl((rlockobject *)self, state); |
538 | |
|
539 | 0 | return return_value; |
540 | 0 | } |
541 | | |
542 | | PyDoc_STRVAR(_thread_RLock__release_save__doc__, |
543 | | "_release_save($self, /)\n" |
544 | | "--\n" |
545 | | "\n" |
546 | | "For internal use by `threading.Condition`."); |
547 | | |
548 | | #define _THREAD_RLOCK__RELEASE_SAVE_METHODDEF \ |
549 | | {"_release_save", (PyCFunction)_thread_RLock__release_save, METH_NOARGS, _thread_RLock__release_save__doc__}, |
550 | | |
551 | | static PyObject * |
552 | | _thread_RLock__release_save_impl(rlockobject *self); |
553 | | |
554 | | static PyObject * |
555 | | _thread_RLock__release_save(PyObject *self, PyObject *Py_UNUSED(ignored)) |
556 | 0 | { |
557 | 0 | return _thread_RLock__release_save_impl((rlockobject *)self); |
558 | 0 | } |
559 | | |
560 | | PyDoc_STRVAR(_thread_RLock__recursion_count__doc__, |
561 | | "_recursion_count($self, /)\n" |
562 | | "--\n" |
563 | | "\n" |
564 | | "For internal use by reentrancy checks."); |
565 | | |
566 | | #define _THREAD_RLOCK__RECURSION_COUNT_METHODDEF \ |
567 | | {"_recursion_count", (PyCFunction)_thread_RLock__recursion_count, METH_NOARGS, _thread_RLock__recursion_count__doc__}, |
568 | | |
569 | | static PyObject * |
570 | | _thread_RLock__recursion_count_impl(rlockobject *self); |
571 | | |
572 | | static PyObject * |
573 | | _thread_RLock__recursion_count(PyObject *self, PyObject *Py_UNUSED(ignored)) |
574 | 0 | { |
575 | 0 | return _thread_RLock__recursion_count_impl((rlockobject *)self); |
576 | 0 | } |
577 | | |
578 | | PyDoc_STRVAR(_thread_RLock__is_owned__doc__, |
579 | | "_is_owned($self, /)\n" |
580 | | "--\n" |
581 | | "\n" |
582 | | "For internal use by `threading.Condition`."); |
583 | | |
584 | | #define _THREAD_RLOCK__IS_OWNED_METHODDEF \ |
585 | | {"_is_owned", (PyCFunction)_thread_RLock__is_owned, METH_NOARGS, _thread_RLock__is_owned__doc__}, |
586 | | |
587 | | static PyObject * |
588 | | _thread_RLock__is_owned_impl(rlockobject *self); |
589 | | |
590 | | static PyObject * |
591 | | _thread_RLock__is_owned(PyObject *self, PyObject *Py_UNUSED(ignored)) |
592 | 0 | { |
593 | 0 | return _thread_RLock__is_owned_impl((rlockobject *)self); |
594 | 0 | } |
595 | | |
596 | | static PyObject * |
597 | | rlock_new_impl(PyTypeObject *type); |
598 | | |
599 | | static PyObject * |
600 | | rlock_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
601 | 2.66k | { |
602 | 2.66k | PyObject *return_value = NULL; |
603 | 2.66k | PyTypeObject *base_tp = clinic_state()->rlock_type; |
604 | | |
605 | 2.66k | if ((type == base_tp || type->tp_init == base_tp->tp_init) && |
606 | 2.66k | !_PyArg_NoPositional("RLock", args)) { |
607 | 0 | goto exit; |
608 | 0 | } |
609 | 2.66k | if ((type == base_tp || type->tp_init == base_tp->tp_init) && |
610 | 2.66k | !_PyArg_NoKeywords("RLock", kwargs)) { |
611 | 0 | goto exit; |
612 | 0 | } |
613 | 2.66k | return_value = rlock_new_impl(type); |
614 | | |
615 | 2.66k | exit: |
616 | 2.66k | return return_value; |
617 | 2.66k | } |
618 | | |
619 | | #if defined(HAVE_FORK) |
620 | | |
621 | | PyDoc_STRVAR(_thread_RLock__at_fork_reinit__doc__, |
622 | | "_at_fork_reinit($self, /)\n" |
623 | | "--\n" |
624 | | "\n"); |
625 | | |
626 | | #define _THREAD_RLOCK__AT_FORK_REINIT_METHODDEF \ |
627 | | {"_at_fork_reinit", (PyCFunction)_thread_RLock__at_fork_reinit, METH_NOARGS, _thread_RLock__at_fork_reinit__doc__}, |
628 | | |
629 | | static PyObject * |
630 | | _thread_RLock__at_fork_reinit_impl(rlockobject *self); |
631 | | |
632 | | static PyObject * |
633 | | _thread_RLock__at_fork_reinit(PyObject *self, PyObject *Py_UNUSED(ignored)) |
634 | 0 | { |
635 | 0 | return _thread_RLock__at_fork_reinit_impl((rlockobject *)self); |
636 | 0 | } |
637 | | |
638 | | #endif /* defined(HAVE_FORK) */ |
639 | | |
640 | | #if (defined(HAVE_PTHREAD_GETNAME_NP) || defined(HAVE_PTHREAD_GET_NAME_NP) || defined(MS_WINDOWS)) |
641 | | |
642 | | PyDoc_STRVAR(_thread__get_name__doc__, |
643 | | "_get_name($module, /)\n" |
644 | | "--\n" |
645 | | "\n" |
646 | | "Get the name of the current thread."); |
647 | | |
648 | | #define _THREAD__GET_NAME_METHODDEF \ |
649 | | {"_get_name", (PyCFunction)_thread__get_name, METH_NOARGS, _thread__get_name__doc__}, |
650 | | |
651 | | static PyObject * |
652 | | _thread__get_name_impl(PyObject *module); |
653 | | |
654 | | static PyObject * |
655 | | _thread__get_name(PyObject *module, PyObject *Py_UNUSED(ignored)) |
656 | 0 | { |
657 | 0 | return _thread__get_name_impl(module); |
658 | 0 | } |
659 | | |
660 | | #endif /* (defined(HAVE_PTHREAD_GETNAME_NP) || defined(HAVE_PTHREAD_GET_NAME_NP) || defined(MS_WINDOWS)) */ |
661 | | |
662 | | #if (defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SET_NAME_NP) || defined(MS_WINDOWS)) |
663 | | |
664 | | PyDoc_STRVAR(_thread_set_name__doc__, |
665 | | "set_name($module, /, name)\n" |
666 | | "--\n" |
667 | | "\n" |
668 | | "Set the name of the current thread."); |
669 | | |
670 | | #define _THREAD_SET_NAME_METHODDEF \ |
671 | | {"set_name", _PyCFunction_CAST(_thread_set_name), METH_FASTCALL|METH_KEYWORDS, _thread_set_name__doc__}, |
672 | | |
673 | | static PyObject * |
674 | | _thread_set_name_impl(PyObject *module, PyObject *name_obj); |
675 | | |
676 | | static PyObject * |
677 | | _thread_set_name(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
678 | 0 | { |
679 | 0 | PyObject *return_value = NULL; |
680 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
681 | |
|
682 | 0 | #define NUM_KEYWORDS 1 |
683 | 0 | static struct { |
684 | 0 | PyGC_Head _this_is_not_used; |
685 | 0 | PyObject_VAR_HEAD |
686 | 0 | Py_hash_t ob_hash; |
687 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
688 | 0 | } _kwtuple = { |
689 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
690 | 0 | .ob_hash = -1, |
691 | 0 | .ob_item = { &_Py_ID(name), }, |
692 | 0 | }; |
693 | 0 | #undef NUM_KEYWORDS |
694 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
695 | |
|
696 | | #else // !Py_BUILD_CORE |
697 | | # define KWTUPLE NULL |
698 | | #endif // !Py_BUILD_CORE |
699 | |
|
700 | 0 | static const char * const _keywords[] = {"name", NULL}; |
701 | 0 | static _PyArg_Parser _parser = { |
702 | 0 | .keywords = _keywords, |
703 | 0 | .fname = "set_name", |
704 | 0 | .kwtuple = KWTUPLE, |
705 | 0 | }; |
706 | 0 | #undef KWTUPLE |
707 | 0 | PyObject *argsbuf[1]; |
708 | 0 | PyObject *name_obj; |
709 | |
|
710 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
711 | 0 | /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
712 | 0 | if (!args) { |
713 | 0 | goto exit; |
714 | 0 | } |
715 | 0 | if (!PyUnicode_Check(args[0])) { |
716 | 0 | _PyArg_BadArgument("set_name", "argument 'name'", "str", args[0]); |
717 | 0 | goto exit; |
718 | 0 | } |
719 | 0 | name_obj = args[0]; |
720 | 0 | return_value = _thread_set_name_impl(module, name_obj); |
721 | |
|
722 | 0 | exit: |
723 | 0 | return return_value; |
724 | 0 | } |
725 | | |
726 | | #endif /* (defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SET_NAME_NP) || defined(MS_WINDOWS)) */ |
727 | | |
728 | | #ifndef _THREAD_LOCK__AT_FORK_REINIT_METHODDEF |
729 | | #define _THREAD_LOCK__AT_FORK_REINIT_METHODDEF |
730 | | #endif /* !defined(_THREAD_LOCK__AT_FORK_REINIT_METHODDEF) */ |
731 | | |
732 | | #ifndef _THREAD_RLOCK__AT_FORK_REINIT_METHODDEF |
733 | | #define _THREAD_RLOCK__AT_FORK_REINIT_METHODDEF |
734 | | #endif /* !defined(_THREAD_RLOCK__AT_FORK_REINIT_METHODDEF) */ |
735 | | |
736 | | #ifndef _THREAD__GET_NAME_METHODDEF |
737 | | #define _THREAD__GET_NAME_METHODDEF |
738 | | #endif /* !defined(_THREAD__GET_NAME_METHODDEF) */ |
739 | | |
740 | | #ifndef _THREAD_SET_NAME_METHODDEF |
741 | | #define _THREAD_SET_NAME_METHODDEF |
742 | | #endif /* !defined(_THREAD_SET_NAME_METHODDEF) */ |
743 | | /*[clinic end generated code: output=1255a1520f43f97a input=a9049054013a1b77]*/ |