Coverage Report

Created: 2026-10-17 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Modules/clinic/_threadmodule.c.h
Line
Count
Source
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_abstract.h"      // _PyNumber_Index()
10
#include "pycore_modsupport.h"    // _PyArg_CheckPositional()
11
12
static PyObject *
13
_thread__ThreadHandle_ident_get_impl(PyObject *self);
14
15
static PyObject *
16
_thread__ThreadHandle_ident_get(PyObject *self, void *Py_UNUSED(context))
17
0
{
18
0
    return _thread__ThreadHandle_ident_get_impl(self);
19
0
}
20
21
PyDoc_STRVAR(_thread__ThreadHandle_join__doc__,
22
"join($self, timeout=None, /)\n"
23
"--\n"
24
"\n");
25
26
#define _THREAD__THREADHANDLE_JOIN_METHODDEF    \
27
    {"join", _PyCFunction_CAST(_thread__ThreadHandle_join), METH_FASTCALL, _thread__ThreadHandle_join__doc__},
28
29
static PyObject *
30
_thread__ThreadHandle_join_impl(PyObject *self, PyObject *timeout_obj);
31
32
static PyObject *
33
_thread__ThreadHandle_join(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
34
0
{
35
0
    PyObject *return_value = NULL;
36
0
    PyObject *timeout_obj = Py_None;
37
38
0
    if (!_PyArg_CheckPositional("join", nargs, 0, 1)) {
39
0
        goto exit;
40
0
    }
41
0
    if (nargs < 1) {
42
0
        goto skip_optional;
43
0
    }
44
0
    timeout_obj = args[0];
45
0
skip_optional:
46
0
    return_value = _thread__ThreadHandle_join_impl(self, timeout_obj);
47
48
0
exit:
49
0
    return return_value;
50
0
}
51
52
PyDoc_STRVAR(_thread__ThreadHandle_is_done__doc__,
53
"is_done($self, /)\n"
54
"--\n"
55
"\n");
56
57
#define _THREAD__THREADHANDLE_IS_DONE_METHODDEF    \
58
    {"is_done", (PyCFunction)_thread__ThreadHandle_is_done, METH_NOARGS, _thread__ThreadHandle_is_done__doc__},
59
60
static PyObject *
61
_thread__ThreadHandle_is_done_impl(PyObject *self);
62
63
static PyObject *
64
_thread__ThreadHandle_is_done(PyObject *self, PyObject *Py_UNUSED(ignored))
65
0
{
66
0
    return _thread__ThreadHandle_is_done_impl(self);
67
0
}
68
69
PyDoc_STRVAR(_thread__ThreadHandle__set_done__doc__,
70
"_set_done($self, /)\n"
71
"--\n"
72
"\n");
73
74
#define _THREAD__THREADHANDLE__SET_DONE_METHODDEF    \
75
    {"_set_done", (PyCFunction)_thread__ThreadHandle__set_done, METH_NOARGS, _thread__ThreadHandle__set_done__doc__},
76
77
static PyObject *
78
_thread__ThreadHandle__set_done_impl(PyObject *self);
79
80
static PyObject *
81
_thread__ThreadHandle__set_done(PyObject *self, PyObject *Py_UNUSED(ignored))
82
0
{
83
0
    return _thread__ThreadHandle__set_done_impl(self);
84
0
}
85
86
PyDoc_STRVAR(_thread_lock_acquire__doc__,
87
"acquire($self, /, blocking=True, timeout=-1)\n"
88
"--\n"
89
"\n"
90
"Lock the lock.\n"
91
"\n"
92
"Without argument, this blocks if the lock is already locked\n"
93
"(even by the same thread), waiting for another thread to release\n"
94
"the lock, and return True once the lock is acquired.\n"
95
"With an argument, this will only block if the argument is true,\n"
96
"and the return value reflects whether the lock is acquired.\n"
97
"The blocking operation is interruptible.");
98
99
#define _THREAD_LOCK_ACQUIRE_METHODDEF    \
100
    {"acquire", _PyCFunction_CAST(_thread_lock_acquire), METH_FASTCALL|METH_KEYWORDS, _thread_lock_acquire__doc__},
101
102
static PyObject *
103
_thread_lock_acquire_impl(lockobject *self, int blocking,
104
                          PyObject *timeoutobj);
105
106
static PyObject *
107
_thread_lock_acquire(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
108
16
{
109
16
    PyObject *return_value = NULL;
110
16
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
111
112
16
    #define NUM_KEYWORDS 2
113
16
    static struct {
114
16
        PyGC_Head _this_is_not_used;
115
16
        PyObject_VAR_HEAD
116
16
        Py_hash_t ob_hash;
117
16
        PyObject *ob_item[NUM_KEYWORDS];
118
16
    } _kwtuple = {
119
16
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
120
16
        .ob_hash = -1,
121
16
        .ob_item = { &_Py_ID(blocking), &_Py_ID(timeout), },
122
16
    };
123
16
    #undef NUM_KEYWORDS
124
16
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
125
126
    #else  // !Py_BUILD_CORE
127
    #  define KWTUPLE NULL
128
    #endif  // !Py_BUILD_CORE
129
130
16
    static const char * const _keywords[] = {"blocking", "timeout", NULL};
131
16
    static _PyArg_Parser _parser = {
132
16
        .keywords = _keywords,
133
16
        .fname = "acquire",
134
16
        .kwtuple = KWTUPLE,
135
16
    };
136
16
    #undef KWTUPLE
137
16
    PyObject *argsbuf[2];
138
16
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
139
16
    int blocking = 1;
140
16
    PyObject *timeoutobj = NULL;
141
142
16
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
143
16
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
144
16
    if (!args) {
145
0
        goto exit;
146
0
    }
147
16
    if (!noptargs) {
148
8
        goto skip_optional_pos;
149
8
    }
150
8
    if (args[0]) {
151
8
        blocking = PyObject_IsTrue(args[0]);
152
8
        if (blocking < 0) {
153
0
            goto exit;
154
0
        }
155
8
        if (!--noptargs) {
156
8
            goto skip_optional_pos;
157
8
        }
158
8
    }
159
0
    timeoutobj = args[1];
160
16
skip_optional_pos:
161
16
    return_value = _thread_lock_acquire_impl((lockobject *)self, blocking, timeoutobj);
162
163
16
exit:
164
16
    return return_value;
165
16
}
166
167
PyDoc_STRVAR(_thread_lock_acquire_lock__doc__,
168
"acquire_lock($self, /, blocking=True, timeout=-1)\n"
169
"--\n"
170
"\n"
171
"An obsolete synonym of acquire().");
172
173
#define _THREAD_LOCK_ACQUIRE_LOCK_METHODDEF    \
174
    {"acquire_lock", _PyCFunction_CAST(_thread_lock_acquire_lock), METH_FASTCALL|METH_KEYWORDS, _thread_lock_acquire_lock__doc__},
175
176
static PyObject *
177
_thread_lock_acquire_lock_impl(lockobject *self, int blocking,
178
                               PyObject *timeoutobj);
179
180
static PyObject *
181
_thread_lock_acquire_lock(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
182
0
{
183
0
    PyObject *return_value = NULL;
184
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
185
186
0
    #define NUM_KEYWORDS 2
187
0
    static struct {
188
0
        PyGC_Head _this_is_not_used;
189
0
        PyObject_VAR_HEAD
190
0
        Py_hash_t ob_hash;
191
0
        PyObject *ob_item[NUM_KEYWORDS];
192
0
    } _kwtuple = {
193
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
194
0
        .ob_hash = -1,
195
0
        .ob_item = { &_Py_ID(blocking), &_Py_ID(timeout), },
196
0
    };
197
0
    #undef NUM_KEYWORDS
198
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
199
200
    #else  // !Py_BUILD_CORE
201
    #  define KWTUPLE NULL
202
    #endif  // !Py_BUILD_CORE
203
204
0
    static const char * const _keywords[] = {"blocking", "timeout", NULL};
205
0
    static _PyArg_Parser _parser = {
206
0
        .keywords = _keywords,
207
0
        .fname = "acquire_lock",
208
0
        .kwtuple = KWTUPLE,
209
0
    };
210
0
    #undef KWTUPLE
211
0
    PyObject *argsbuf[2];
212
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
213
0
    int blocking = 1;
214
0
    PyObject *timeoutobj = NULL;
215
216
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
217
0
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
218
0
    if (!args) {
219
0
        goto exit;
220
0
    }
221
0
    if (!noptargs) {
222
0
        goto skip_optional_pos;
223
0
    }
224
0
    if (args[0]) {
225
0
        blocking = PyObject_IsTrue(args[0]);
226
0
        if (blocking < 0) {
227
0
            goto exit;
228
0
        }
229
0
        if (!--noptargs) {
230
0
            goto skip_optional_pos;
231
0
        }
232
0
    }
233
0
    timeoutobj = args[1];
234
0
skip_optional_pos:
235
0
    return_value = _thread_lock_acquire_lock_impl((lockobject *)self, blocking, timeoutobj);
236
237
0
exit:
238
0
    return return_value;
239
0
}
240
241
PyDoc_STRVAR(_thread_lock_release__doc__,
242
"release($self, /)\n"
243
"--\n"
244
"\n"
245
"Release the lock.\n"
246
"\n"
247
"Allows another thread that is blocked waiting for\n"
248
"the lock to acquire the lock.  The lock must be in the locked state,\n"
249
"but it needn\'t be locked by the same thread that unlocks it.");
250
251
#define _THREAD_LOCK_RELEASE_METHODDEF    \
252
    {"release", (PyCFunction)_thread_lock_release, METH_NOARGS, _thread_lock_release__doc__},
253
254
static PyObject *
255
_thread_lock_release_impl(lockobject *self);
256
257
static PyObject *
258
_thread_lock_release(PyObject *self, PyObject *Py_UNUSED(ignored))
259
8
{
260
8
    return _thread_lock_release_impl((lockobject *)self);
261
8
}
262
263
PyDoc_STRVAR(_thread_lock_release_lock__doc__,
264
"release_lock($self, /)\n"
265
"--\n"
266
"\n"
267
"An obsolete synonym of release().");
268
269
#define _THREAD_LOCK_RELEASE_LOCK_METHODDEF    \
270
    {"release_lock", (PyCFunction)_thread_lock_release_lock, METH_NOARGS, _thread_lock_release_lock__doc__},
271
272
static PyObject *
273
_thread_lock_release_lock_impl(lockobject *self);
274
275
static PyObject *
276
_thread_lock_release_lock(PyObject *self, PyObject *Py_UNUSED(ignored))
277
0
{
278
0
    return _thread_lock_release_lock_impl((lockobject *)self);
279
0
}
280
281
PyDoc_STRVAR(_thread_lock___enter____doc__,
282
"__enter__($self, /)\n"
283
"--\n"
284
"\n"
285
"Lock the lock.");
286
287
#define _THREAD_LOCK___ENTER___METHODDEF    \
288
    {"__enter__", (PyCFunction)_thread_lock___enter__, METH_NOARGS, _thread_lock___enter____doc__},
289
290
static PyObject *
291
_thread_lock___enter___impl(lockobject *self);
292
293
static PyObject *
294
_thread_lock___enter__(PyObject *self, PyObject *Py_UNUSED(ignored))
295
398
{
296
398
    return _thread_lock___enter___impl((lockobject *)self);
297
398
}
298
299
PyDoc_STRVAR(_thread_lock___exit____doc__,
300
"__exit__($self, exc_type, exc_value, exc_tb, /)\n"
301
"--\n"
302
"\n"
303
"Release the lock.");
304
305
#define _THREAD_LOCK___EXIT___METHODDEF    \
306
    {"__exit__", _PyCFunction_CAST(_thread_lock___exit__), METH_FASTCALL, _thread_lock___exit____doc__},
307
308
static PyObject *
309
_thread_lock___exit___impl(lockobject *self, PyObject *exc_type,
310
                           PyObject *exc_value, PyObject *exc_tb);
311
312
static PyObject *
313
_thread_lock___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
314
398
{
315
398
    PyObject *return_value = NULL;
316
398
    PyObject *exc_type;
317
398
    PyObject *exc_value;
318
398
    PyObject *exc_tb;
319
320
398
    if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
321
0
        goto exit;
322
0
    }
323
398
    exc_type = args[0];
324
398
    exc_value = args[1];
325
398
    exc_tb = args[2];
326
398
    return_value = _thread_lock___exit___impl((lockobject *)self, exc_type, exc_value, exc_tb);
327
328
398
exit:
329
398
    return return_value;
330
398
}
331
332
PyDoc_STRVAR(_thread_lock_locked__doc__,
333
"locked($self, /)\n"
334
"--\n"
335
"\n"
336
"Return whether the lock is in the locked state.");
337
338
#define _THREAD_LOCK_LOCKED_METHODDEF    \
339
    {"locked", (PyCFunction)_thread_lock_locked, METH_NOARGS, _thread_lock_locked__doc__},
340
341
static PyObject *
342
_thread_lock_locked_impl(lockobject *self);
343
344
static PyObject *
345
_thread_lock_locked(PyObject *self, PyObject *Py_UNUSED(ignored))
346
0
{
347
0
    return _thread_lock_locked_impl((lockobject *)self);
348
0
}
349
350
PyDoc_STRVAR(_thread_lock_locked_lock__doc__,
351
"locked_lock($self, /)\n"
352
"--\n"
353
"\n"
354
"An obsolete synonym of locked().");
355
356
#define _THREAD_LOCK_LOCKED_LOCK_METHODDEF    \
357
    {"locked_lock", (PyCFunction)_thread_lock_locked_lock, METH_NOARGS, _thread_lock_locked_lock__doc__},
358
359
static PyObject *
360
_thread_lock_locked_lock_impl(lockobject *self);
361
362
static PyObject *
363
_thread_lock_locked_lock(PyObject *self, PyObject *Py_UNUSED(ignored))
364
0
{
365
0
    return _thread_lock_locked_lock_impl((lockobject *)self);
366
0
}
367
368
#if defined(HAVE_FORK)
369
370
PyDoc_STRVAR(_thread_lock__at_fork_reinit__doc__,
371
"_at_fork_reinit($self, /)\n"
372
"--\n"
373
"\n");
374
375
#define _THREAD_LOCK__AT_FORK_REINIT_METHODDEF    \
376
    {"_at_fork_reinit", (PyCFunction)_thread_lock__at_fork_reinit, METH_NOARGS, _thread_lock__at_fork_reinit__doc__},
377
378
static PyObject *
379
_thread_lock__at_fork_reinit_impl(lockobject *self);
380
381
static PyObject *
382
_thread_lock__at_fork_reinit(PyObject *self, PyObject *Py_UNUSED(ignored))
383
0
{
384
0
    return _thread_lock__at_fork_reinit_impl((lockobject *)self);
385
0
}
386
387
#endif /* defined(HAVE_FORK) */
388
389
static PyObject *
390
lock_new_impl(PyTypeObject *type);
391
392
static PyObject *
393
lock_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
394
24
{
395
24
    PyObject *return_value = NULL;
396
24
    PyTypeObject *base_tp = clinic_state()->lock_type;
397
398
24
    if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
399
24
        !_PyArg_NoPositional("lock", args)) {
400
0
        goto exit;
401
0
    }
402
24
    if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
403
24
        !_PyArg_NoKeywords("lock", kwargs)) {
404
0
        goto exit;
405
0
    }
406
24
    return_value = lock_new_impl(type);
407
408
24
exit:
409
24
    return return_value;
410
24
}
411
412
PyDoc_STRVAR(_thread_RLock_acquire__doc__,
413
"acquire($self, /, blocking=True, timeout=-1)\n"
414
"--\n"
415
"\n"
416
"Lock the lock.\n"
417
"\n"
418
"`blocking` indicates whether we should wait\n"
419
"for the lock to be available or not.  If `blocking` is False\n"
420
"and another thread holds the lock, the method will return False\n"
421
"immediately.  If `blocking` is True and another thread holds\n"
422
"the lock, the method will wait for the lock to be released,\n"
423
"take it and then return True.\n"
424
"(note: the blocking operation is interruptible.)\n"
425
"\n"
426
"In all other cases, the method will return True immediately.\n"
427
"Precisely, if the current thread already holds the lock, its\n"
428
"internal counter is simply incremented. If nobody holds the lock,\n"
429
"the lock is taken and its internal counter initialized to 1.");
430
431
#define _THREAD_RLOCK_ACQUIRE_METHODDEF    \
432
    {"acquire", _PyCFunction_CAST(_thread_RLock_acquire), METH_FASTCALL|METH_KEYWORDS, _thread_RLock_acquire__doc__},
433
434
static PyObject *
435
_thread_RLock_acquire_impl(rlockobject *self, int blocking,
436
                           PyObject *timeoutobj);
437
438
static PyObject *
439
_thread_RLock_acquire(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
440
0
{
441
0
    PyObject *return_value = NULL;
442
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
443
444
0
    #define NUM_KEYWORDS 2
445
0
    static struct {
446
0
        PyGC_Head _this_is_not_used;
447
0
        PyObject_VAR_HEAD
448
0
        Py_hash_t ob_hash;
449
0
        PyObject *ob_item[NUM_KEYWORDS];
450
0
    } _kwtuple = {
451
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
452
0
        .ob_hash = -1,
453
0
        .ob_item = { &_Py_ID(blocking), &_Py_ID(timeout), },
454
0
    };
455
0
    #undef NUM_KEYWORDS
456
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
457
458
    #else  // !Py_BUILD_CORE
459
    #  define KWTUPLE NULL
460
    #endif  // !Py_BUILD_CORE
461
462
0
    static const char * const _keywords[] = {"blocking", "timeout", NULL};
463
0
    static _PyArg_Parser _parser = {
464
0
        .keywords = _keywords,
465
0
        .fname = "acquire",
466
0
        .kwtuple = KWTUPLE,
467
0
    };
468
0
    #undef KWTUPLE
469
0
    PyObject *argsbuf[2];
470
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
471
0
    int blocking = 1;
472
0
    PyObject *timeoutobj = NULL;
473
474
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
475
0
            /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
476
0
    if (!args) {
477
0
        goto exit;
478
0
    }
479
0
    if (!noptargs) {
480
0
        goto skip_optional_pos;
481
0
    }
482
0
    if (args[0]) {
483
0
        blocking = PyObject_IsTrue(args[0]);
484
0
        if (blocking < 0) {
485
0
            goto exit;
486
0
        }
487
0
        if (!--noptargs) {
488
0
            goto skip_optional_pos;
489
0
        }
490
0
    }
491
0
    timeoutobj = args[1];
492
0
skip_optional_pos:
493
0
    return_value = _thread_RLock_acquire_impl((rlockobject *)self, blocking, timeoutobj);
494
495
0
exit:
496
0
    return return_value;
497
0
}
498
499
PyDoc_STRVAR(_thread_RLock___enter____doc__,
500
"__enter__($self, /)\n"
501
"--\n"
502
"\n"
503
"Lock the lock.");
504
505
#define _THREAD_RLOCK___ENTER___METHODDEF    \
506
    {"__enter__", (PyCFunction)_thread_RLock___enter__, METH_NOARGS, _thread_RLock___enter____doc__},
507
508
static PyObject *
509
_thread_RLock___enter___impl(rlockobject *self);
510
511
static PyObject *
512
_thread_RLock___enter__(PyObject *self, PyObject *Py_UNUSED(ignored))
513
183k
{
514
183k
    return _thread_RLock___enter___impl((rlockobject *)self);
515
183k
}
516
517
PyDoc_STRVAR(_thread_RLock_release__doc__,
518
"release($self, /)\n"
519
"--\n"
520
"\n"
521
"Release the lock.\n"
522
"\n"
523
"Allows another thread that is blocked waiting for the lock\n"
524
"to acquire the lock.  The lock must be in the locked state,\n"
525
"and must be locked by the same thread that unlocks it; otherwise a\n"
526
"`RuntimeError` is raised.\n"
527
"\n"
528
"Do note that if the lock was acquire()d several times in a row by\n"
529
"the current thread, release() needs to be called as many times for\n"
530
"the lock to be available for other threads.");
531
532
#define _THREAD_RLOCK_RELEASE_METHODDEF    \
533
    {"release", (PyCFunction)_thread_RLock_release, METH_NOARGS, _thread_RLock_release__doc__},
534
535
static PyObject *
536
_thread_RLock_release_impl(rlockobject *self);
537
538
static PyObject *
539
_thread_RLock_release(PyObject *self, PyObject *Py_UNUSED(ignored))
540
0
{
541
0
    return _thread_RLock_release_impl((rlockobject *)self);
542
0
}
543
544
PyDoc_STRVAR(_thread_RLock___exit____doc__,
545
"__exit__($self, exc_type, exc_value, exc_tb, /)\n"
546
"--\n"
547
"\n"
548
"Release the lock.");
549
550
#define _THREAD_RLOCK___EXIT___METHODDEF    \
551
    {"__exit__", _PyCFunction_CAST(_thread_RLock___exit__), METH_FASTCALL, _thread_RLock___exit____doc__},
552
553
static PyObject *
554
_thread_RLock___exit___impl(rlockobject *self, PyObject *exc_type,
555
                            PyObject *exc_value, PyObject *exc_tb);
556
557
static PyObject *
558
_thread_RLock___exit__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
559
183k
{
560
183k
    PyObject *return_value = NULL;
561
183k
    PyObject *exc_type;
562
183k
    PyObject *exc_value;
563
183k
    PyObject *exc_tb;
564
565
183k
    if (!_PyArg_CheckPositional("__exit__", nargs, 3, 3)) {
566
0
        goto exit;
567
0
    }
568
183k
    exc_type = args[0];
569
183k
    exc_value = args[1];
570
183k
    exc_tb = args[2];
571
183k
    return_value = _thread_RLock___exit___impl((rlockobject *)self, exc_type, exc_value, exc_tb);
572
573
183k
exit:
574
183k
    return return_value;
575
183k
}
576
577
PyDoc_STRVAR(_thread_RLock_locked__doc__,
578
"locked($self, /)\n"
579
"--\n"
580
"\n"
581
"Return a boolean indicating whether this object is locked right now.");
582
583
#define _THREAD_RLOCK_LOCKED_METHODDEF    \
584
    {"locked", (PyCFunction)_thread_RLock_locked, METH_NOARGS, _thread_RLock_locked__doc__},
585
586
static PyObject *
587
_thread_RLock_locked_impl(rlockobject *self);
588
589
static PyObject *
590
_thread_RLock_locked(PyObject *self, PyObject *Py_UNUSED(ignored))
591
0
{
592
0
    return _thread_RLock_locked_impl((rlockobject *)self);
593
0
}
594
595
PyDoc_STRVAR(_thread_RLock__acquire_restore__doc__,
596
"_acquire_restore($self, state, /)\n"
597
"--\n"
598
"\n"
599
"For internal use by `threading.Condition`.");
600
601
#define _THREAD_RLOCK__ACQUIRE_RESTORE_METHODDEF    \
602
    {"_acquire_restore", (PyCFunction)_thread_RLock__acquire_restore, METH_O, _thread_RLock__acquire_restore__doc__},
603
604
static PyObject *
605
_thread_RLock__acquire_restore_impl(rlockobject *self, PyObject *state);
606
607
static PyObject *
608
_thread_RLock__acquire_restore(PyObject *self, PyObject *state)
609
0
{
610
0
    PyObject *return_value = NULL;
611
612
0
    return_value = _thread_RLock__acquire_restore_impl((rlockobject *)self, state);
613
614
0
    return return_value;
615
0
}
616
617
PyDoc_STRVAR(_thread_RLock__release_save__doc__,
618
"_release_save($self, /)\n"
619
"--\n"
620
"\n"
621
"For internal use by `threading.Condition`.");
622
623
#define _THREAD_RLOCK__RELEASE_SAVE_METHODDEF    \
624
    {"_release_save", (PyCFunction)_thread_RLock__release_save, METH_NOARGS, _thread_RLock__release_save__doc__},
625
626
static PyObject *
627
_thread_RLock__release_save_impl(rlockobject *self);
628
629
static PyObject *
630
_thread_RLock__release_save(PyObject *self, PyObject *Py_UNUSED(ignored))
631
0
{
632
0
    return _thread_RLock__release_save_impl((rlockobject *)self);
633
0
}
634
635
PyDoc_STRVAR(_thread_RLock__recursion_count__doc__,
636
"_recursion_count($self, /)\n"
637
"--\n"
638
"\n"
639
"For internal use by reentrancy checks.");
640
641
#define _THREAD_RLOCK__RECURSION_COUNT_METHODDEF    \
642
    {"_recursion_count", (PyCFunction)_thread_RLock__recursion_count, METH_NOARGS, _thread_RLock__recursion_count__doc__},
643
644
static PyObject *
645
_thread_RLock__recursion_count_impl(rlockobject *self);
646
647
static PyObject *
648
_thread_RLock__recursion_count(PyObject *self, PyObject *Py_UNUSED(ignored))
649
0
{
650
0
    return _thread_RLock__recursion_count_impl((rlockobject *)self);
651
0
}
652
653
PyDoc_STRVAR(_thread_RLock__is_owned__doc__,
654
"_is_owned($self, /)\n"
655
"--\n"
656
"\n"
657
"For internal use by `threading.Condition`.");
658
659
#define _THREAD_RLOCK__IS_OWNED_METHODDEF    \
660
    {"_is_owned", (PyCFunction)_thread_RLock__is_owned, METH_NOARGS, _thread_RLock__is_owned__doc__},
661
662
static PyObject *
663
_thread_RLock__is_owned_impl(rlockobject *self);
664
665
static PyObject *
666
_thread_RLock__is_owned(PyObject *self, PyObject *Py_UNUSED(ignored))
667
0
{
668
0
    return _thread_RLock__is_owned_impl((rlockobject *)self);
669
0
}
670
671
static PyObject *
672
rlock_new_impl(PyTypeObject *type);
673
674
static PyObject *
675
rlock_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
676
23.9k
{
677
23.9k
    PyObject *return_value = NULL;
678
23.9k
    PyTypeObject *base_tp = clinic_state()->rlock_type;
679
680
23.9k
    if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
681
23.9k
        !_PyArg_NoPositional("RLock", args)) {
682
0
        goto exit;
683
0
    }
684
23.9k
    if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
685
23.9k
        !_PyArg_NoKeywords("RLock", kwargs)) {
686
0
        goto exit;
687
0
    }
688
23.9k
    return_value = rlock_new_impl(type);
689
690
23.9k
exit:
691
23.9k
    return return_value;
692
23.9k
}
693
694
#if defined(HAVE_FORK)
695
696
PyDoc_STRVAR(_thread_RLock__at_fork_reinit__doc__,
697
"_at_fork_reinit($self, /)\n"
698
"--\n"
699
"\n");
700
701
#define _THREAD_RLOCK__AT_FORK_REINIT_METHODDEF    \
702
    {"_at_fork_reinit", (PyCFunction)_thread_RLock__at_fork_reinit, METH_NOARGS, _thread_RLock__at_fork_reinit__doc__},
703
704
static PyObject *
705
_thread_RLock__at_fork_reinit_impl(rlockobject *self);
706
707
static PyObject *
708
_thread_RLock__at_fork_reinit(PyObject *self, PyObject *Py_UNUSED(ignored))
709
0
{
710
0
    return _thread_RLock__at_fork_reinit_impl((rlockobject *)self);
711
0
}
712
713
#endif /* defined(HAVE_FORK) */
714
715
PyDoc_STRVAR(_thread_daemon_threads_allowed__doc__,
716
"daemon_threads_allowed($module, /)\n"
717
"--\n"
718
"\n"
719
"Return True if daemon threads are allowed in the current interpreter.\n"
720
"\n"
721
"Return False otherwise.");
722
723
#define _THREAD_DAEMON_THREADS_ALLOWED_METHODDEF    \
724
    {"daemon_threads_allowed", (PyCFunction)_thread_daemon_threads_allowed, METH_NOARGS, _thread_daemon_threads_allowed__doc__},
725
726
static PyObject *
727
_thread_daemon_threads_allowed_impl(PyObject *module);
728
729
static PyObject *
730
_thread_daemon_threads_allowed(PyObject *module, PyObject *Py_UNUSED(ignored))
731
0
{
732
0
    return _thread_daemon_threads_allowed_impl(module);
733
0
}
734
735
PyDoc_STRVAR(_thread_start_new_thread__doc__,
736
"start_new_thread($module, function, args, kwargs={}, /)\n"
737
"--\n"
738
"\n"
739
"Start a new thread and return its identifier.\n"
740
"\n"
741
"The thread will call the function with positional arguments from the\n"
742
"tuple args and keyword arguments taken from the optional dictionary\n"
743
"kwargs.  The thread exits when the function returns; the return value\n"
744
"is ignored.  The thread will also exit when the function raises an\n"
745
"unhandled exception; a stack trace will be printed unless the exception\n"
746
"is SystemExit.");
747
748
#define _THREAD_START_NEW_THREAD_METHODDEF    \
749
    {"start_new_thread", _PyCFunction_CAST(_thread_start_new_thread), METH_FASTCALL, _thread_start_new_thread__doc__},
750
751
static PyObject *
752
_thread_start_new_thread_impl(PyObject *module, PyObject *func,
753
                              PyObject *args, PyObject *kwargs);
754
755
static PyObject *
756
_thread_start_new_thread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
757
0
{
758
0
    PyObject *return_value = NULL;
759
0
    PyObject *func;
760
0
    PyObject *__clinic_args;
761
0
    PyObject *__clinic_kwargs = NULL;
762
763
0
    if (!_PyArg_CheckPositional("start_new_thread", nargs, 2, 3)) {
764
0
        goto exit;
765
0
    }
766
0
    func = args[0];
767
0
    if (!PyTuple_Check(args[1])) {
768
0
        _PyArg_BadArgument("start_new_thread", "argument 2", "tuple", args[1]);
769
0
        goto exit;
770
0
    }
771
0
    __clinic_args = args[1];
772
0
    if (nargs < 3) {
773
0
        goto skip_optional;
774
0
    }
775
0
    if (!PyDict_Check(args[2])) {
776
0
        _PyArg_BadArgument("start_new_thread", "argument 3", "dict", args[2]);
777
0
        goto exit;
778
0
    }
779
0
    __clinic_kwargs = args[2];
780
0
skip_optional:
781
0
    return_value = _thread_start_new_thread_impl(module, func, __clinic_args, __clinic_kwargs);
782
783
0
exit:
784
0
    return return_value;
785
0
}
786
787
PyDoc_STRVAR(_thread_start_joinable_thread__doc__,
788
"start_joinable_thread($module, /, function, handle=None, daemon=True)\n"
789
"--\n"
790
"\n"
791
"*For internal use only*: start a new thread.\n"
792
"\n"
793
"Like start_new_thread(), this starts a new thread calling the given\n"
794
"function.  Unlike start_new_thread(), this returns a handle object with\n"
795
"methods to join or detach the given thread.\n"
796
"This function is not for third-party code, please use the `threading`\n"
797
"module instead.  During finalization the runtime will not wait for the\n"
798
"thread to exit if daemon is True.  If handle is provided it must be a\n"
799
"newly created thread._ThreadHandle instance.");
800
801
#define _THREAD_START_JOINABLE_THREAD_METHODDEF    \
802
    {"start_joinable_thread", _PyCFunction_CAST(_thread_start_joinable_thread), METH_FASTCALL|METH_KEYWORDS, _thread_start_joinable_thread__doc__},
803
804
static PyObject *
805
_thread_start_joinable_thread_impl(PyObject *module, PyObject *func,
806
                                   PyObject *hobj, int daemon);
807
808
static PyObject *
809
_thread_start_joinable_thread(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
810
0
{
811
0
    PyObject *return_value = NULL;
812
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
813
814
0
    #define NUM_KEYWORDS 3
815
0
    static struct {
816
0
        PyGC_Head _this_is_not_used;
817
0
        PyObject_VAR_HEAD
818
0
        Py_hash_t ob_hash;
819
0
        PyObject *ob_item[NUM_KEYWORDS];
820
0
    } _kwtuple = {
821
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
822
0
        .ob_hash = -1,
823
0
        .ob_item = { &_Py_ID(function), &_Py_ID(handle), &_Py_ID(daemon), },
824
0
    };
825
0
    #undef NUM_KEYWORDS
826
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
827
828
    #else  // !Py_BUILD_CORE
829
    #  define KWTUPLE NULL
830
    #endif  // !Py_BUILD_CORE
831
832
0
    static const char * const _keywords[] = {"function", "handle", "daemon", NULL};
833
0
    static _PyArg_Parser _parser = {
834
0
        .keywords = _keywords,
835
0
        .fname = "start_joinable_thread",
836
0
        .kwtuple = KWTUPLE,
837
0
    };
838
0
    #undef KWTUPLE
839
0
    PyObject *argsbuf[3];
840
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
841
0
    PyObject *func;
842
0
    PyObject *hobj = Py_None;
843
0
    int daemon = 1;
844
845
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
846
0
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
847
0
    if (!args) {
848
0
        goto exit;
849
0
    }
850
0
    func = args[0];
851
0
    if (!noptargs) {
852
0
        goto skip_optional_pos;
853
0
    }
854
0
    if (args[1]) {
855
0
        hobj = args[1];
856
0
        if (!--noptargs) {
857
0
            goto skip_optional_pos;
858
0
        }
859
0
    }
860
0
    daemon = PyObject_IsTrue(args[2]);
861
0
    if (daemon < 0) {
862
0
        goto exit;
863
0
    }
864
0
skip_optional_pos:
865
0
    return_value = _thread_start_joinable_thread_impl(module, func, hobj, daemon);
866
867
0
exit:
868
0
    return return_value;
869
0
}
870
871
PyDoc_STRVAR(_thread_exit__doc__,
872
"exit($module, /)\n"
873
"--\n"
874
"\n"
875
"Raise SystemExit.\n"
876
"\n"
877
"It will cause the current thread to exit silently unless the exception\n"
878
"is caught.");
879
880
#define _THREAD_EXIT_METHODDEF    \
881
    {"exit", (PyCFunction)_thread_exit, METH_NOARGS, _thread_exit__doc__},
882
883
static PyObject *
884
_thread_exit_impl(PyObject *module);
885
886
static PyObject *
887
_thread_exit(PyObject *module, PyObject *Py_UNUSED(ignored))
888
0
{
889
0
    return _thread_exit_impl(module);
890
0
}
891
892
PyDoc_STRVAR(_thread_interrupt_main__doc__,
893
"interrupt_main($module, signum=signal.SIGINT, /)\n"
894
"--\n"
895
"\n"
896
"Simulate the arrival of the given signal in the main thread.\n"
897
"\n"
898
"The corresponding signal handler will be executed.\n"
899
"If *signum* is omitted, SIGINT is assumed.\n"
900
"A subthread can use this function to interrupt the main thread.\n"
901
"\n"
902
"Note: the default signal handler for SIGINT raises\n"
903
"``KeyboardInterrupt``.");
904
905
#define _THREAD_INTERRUPT_MAIN_METHODDEF    \
906
    {"interrupt_main", _PyCFunction_CAST(_thread_interrupt_main), METH_FASTCALL, _thread_interrupt_main__doc__},
907
908
static PyObject *
909
_thread_interrupt_main_impl(PyObject *module, int signum);
910
911
static PyObject *
912
_thread_interrupt_main(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
913
0
{
914
0
    PyObject *return_value = NULL;
915
0
    int signum = SIGINT;
916
917
0
    if (!_PyArg_CheckPositional("interrupt_main", nargs, 0, 1)) {
918
0
        goto exit;
919
0
    }
920
0
    if (nargs < 1) {
921
0
        goto skip_optional;
922
0
    }
923
0
    signum = PyLong_AsInt(args[0]);
924
0
    if (signum == -1 && PyErr_Occurred()) {
925
0
        goto exit;
926
0
    }
927
0
skip_optional:
928
0
    return_value = _thread_interrupt_main_impl(module, signum);
929
930
0
exit:
931
0
    return return_value;
932
0
}
933
934
PyDoc_STRVAR(_thread_allocate_lock__doc__,
935
"allocate_lock($module, /)\n"
936
"--\n"
937
"\n"
938
"Create a new lock object.\n"
939
"\n"
940
"See help(type(threading.Lock())) for information about locks.");
941
942
#define _THREAD_ALLOCATE_LOCK_METHODDEF    \
943
    {"allocate_lock", (PyCFunction)_thread_allocate_lock, METH_NOARGS, _thread_allocate_lock__doc__},
944
945
static PyObject *
946
_thread_allocate_lock_impl(PyObject *module);
947
948
static PyObject *
949
_thread_allocate_lock(PyObject *module, PyObject *Py_UNUSED(ignored))
950
12.1k
{
951
12.1k
    return _thread_allocate_lock_impl(module);
952
12.1k
}
953
954
PyDoc_STRVAR(_thread_get_ident__doc__,
955
"get_ident($module, /)\n"
956
"--\n"
957
"\n"
958
"Return a non-zero integer that uniquely identifies the current thread.\n"
959
"\n"
960
"It is unique amongst other threads that exist simultaneously.\n"
961
"This may be used to identify per-thread resources.\n"
962
"Even though on some platforms threads identities may appear to be\n"
963
"allocated consecutive numbers starting at 1, this behavior should not\n"
964
"be relied upon, and the number should be seen purely as a magic cookie.\n"
965
"A thread\'s identity may be reused for another thread after it exits.");
966
967
#define _THREAD_GET_IDENT_METHODDEF    \
968
    {"get_ident", (PyCFunction)_thread_get_ident, METH_NOARGS, _thread_get_ident__doc__},
969
970
static PyObject *
971
_thread_get_ident_impl(PyObject *module);
972
973
static PyObject *
974
_thread_get_ident(PyObject *module, PyObject *Py_UNUSED(ignored))
975
276k
{
976
276k
    return _thread_get_ident_impl(module);
977
276k
}
978
979
#if defined(PY_HAVE_THREAD_NATIVE_ID)
980
981
PyDoc_STRVAR(_thread_get_native_id__doc__,
982
"get_native_id($module, /)\n"
983
"--\n"
984
"\n"
985
"Return a non-negative integer identifying the thread.\n"
986
"\n"
987
"It is reported by the OS (kernel).  This may be used to uniquely\n"
988
"identify a particular thread within a system.");
989
990
#define _THREAD_GET_NATIVE_ID_METHODDEF    \
991
    {"get_native_id", (PyCFunction)_thread_get_native_id, METH_NOARGS, _thread_get_native_id__doc__},
992
993
static PyObject *
994
_thread_get_native_id_impl(PyObject *module);
995
996
static PyObject *
997
_thread_get_native_id(PyObject *module, PyObject *Py_UNUSED(ignored))
998
8
{
999
8
    return _thread_get_native_id_impl(module);
1000
8
}
1001
1002
#endif /* defined(PY_HAVE_THREAD_NATIVE_ID) */
1003
1004
PyDoc_STRVAR(_thread__count__doc__,
1005
"_count($module, /)\n"
1006
"--\n"
1007
"\n"
1008
"Return the number of currently running Python threads.\n"
1009
"\n"
1010
"The main thread is excluded.  The returned number comprises all threads\n"
1011
"created through `start_new_thread()` as well as `threading.Thread`, and\n"
1012
"not yet finished.\n"
1013
"\n"
1014
"This function is meant for internal and specialized purposes only.\n"
1015
"In most applications `threading.enumerate()` should be used instead.");
1016
1017
#define _THREAD__COUNT_METHODDEF    \
1018
    {"_count", (PyCFunction)_thread__count, METH_NOARGS, _thread__count__doc__},
1019
1020
static PyObject *
1021
_thread__count_impl(PyObject *module);
1022
1023
static PyObject *
1024
_thread__count(PyObject *module, PyObject *Py_UNUSED(ignored))
1025
0
{
1026
0
    return _thread__count_impl(module);
1027
0
}
1028
1029
PyDoc_STRVAR(_thread_stack_size__doc__,
1030
"stack_size($module, size=0, /)\n"
1031
"--\n"
1032
"\n"
1033
"Return the thread stack size used when creating new threads.\n"
1034
"\n"
1035
"The optional size argument specifies the stack size (in bytes) to be\n"
1036
"used for subsequently created threads, and must be 0 (use platform or\n"
1037
"configured default) or a positive integer value of at least 32,768 (32\n"
1038
"KiB).  If changing the thread stack size is unsupported, a ThreadError\n"
1039
"exception is raised.  If the specified size is invalid, a ValueError\n"
1040
"exception is raised, and the stack size is unmodified.  32 KiB\n"
1041
"currently is the minimum supported stack size value to guarantee\n"
1042
"sufficient stack space for the interpreter itself.\n"
1043
"\n"
1044
"Note that some systems may have particular restrictions on values for\n"
1045
"the stack size, such as requiring a minimum stack size larger than 32\n"
1046
"KiB or requiring allocation in multiples of the system memory page size\n"
1047
"- platform documentation should be referred to for more information\n"
1048
"(4 KiB pages are common; using multiples of 4096 for the stack size is\n"
1049
"the suggested approach in the absence of more specific information).");
1050
1051
#define _THREAD_STACK_SIZE_METHODDEF    \
1052
    {"stack_size", _PyCFunction_CAST(_thread_stack_size), METH_FASTCALL, _thread_stack_size__doc__},
1053
1054
static PyObject *
1055
_thread_stack_size_impl(PyObject *module, Py_ssize_t new_size);
1056
1057
static PyObject *
1058
_thread_stack_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1059
0
{
1060
0
    PyObject *return_value = NULL;
1061
0
    Py_ssize_t new_size = 0;
1062
1063
0
    if (!_PyArg_CheckPositional("stack_size", nargs, 0, 1)) {
1064
0
        goto exit;
1065
0
    }
1066
0
    if (nargs < 1) {
1067
0
        goto skip_optional;
1068
0
    }
1069
0
    {
1070
0
        Py_ssize_t ival = -1;
1071
0
        PyObject *iobj = _PyNumber_Index(args[0]);
1072
0
        if (iobj != NULL) {
1073
0
            ival = PyLong_AsSsize_t(iobj);
1074
0
            Py_DECREF(iobj);
1075
0
        }
1076
0
        if (ival == -1 && PyErr_Occurred()) {
1077
0
            goto exit;
1078
0
        }
1079
0
        new_size = ival;
1080
0
    }
1081
0
skip_optional:
1082
0
    return_value = _thread_stack_size_impl(module, new_size);
1083
1084
0
exit:
1085
0
    return return_value;
1086
0
}
1087
1088
PyDoc_STRVAR(_thread__excepthook__doc__,
1089
"_excepthook($module, args, /)\n"
1090
"--\n"
1091
"\n"
1092
"Handle uncaught Thread.run() exception.");
1093
1094
#define _THREAD__EXCEPTHOOK_METHODDEF    \
1095
    {"_excepthook", (PyCFunction)_thread__excepthook, METH_O, _thread__excepthook__doc__},
1096
1097
PyDoc_STRVAR(_thread__is_main_interpreter__doc__,
1098
"_is_main_interpreter($module, /)\n"
1099
"--\n"
1100
"\n"
1101
"Return True if the current interpreter is the main Python interpreter.");
1102
1103
#define _THREAD__IS_MAIN_INTERPRETER_METHODDEF    \
1104
    {"_is_main_interpreter", (PyCFunction)_thread__is_main_interpreter, METH_NOARGS, _thread__is_main_interpreter__doc__},
1105
1106
static PyObject *
1107
_thread__is_main_interpreter_impl(PyObject *module);
1108
1109
static PyObject *
1110
_thread__is_main_interpreter(PyObject *module, PyObject *Py_UNUSED(ignored))
1111
0
{
1112
0
    return _thread__is_main_interpreter_impl(module);
1113
0
}
1114
1115
PyDoc_STRVAR(_thread__shutdown__doc__,
1116
"_shutdown($module, /)\n"
1117
"--\n"
1118
"\n"
1119
"Wait for all non-daemon threads (other than the calling thread) to stop.");
1120
1121
#define _THREAD__SHUTDOWN_METHODDEF    \
1122
    {"_shutdown", (PyCFunction)_thread__shutdown, METH_NOARGS, _thread__shutdown__doc__},
1123
1124
static PyObject *
1125
_thread__shutdown_impl(PyObject *module);
1126
1127
static PyObject *
1128
_thread__shutdown(PyObject *module, PyObject *Py_UNUSED(ignored))
1129
0
{
1130
0
    return _thread__shutdown_impl(module);
1131
0
}
1132
1133
PyDoc_STRVAR(_thread__make_thread_handle__doc__,
1134
"_make_thread_handle($module, ident, /)\n"
1135
"--\n"
1136
"\n"
1137
"Internal only.\n"
1138
"\n"
1139
"Make a thread handle for threads not spawned by the _thread or\n"
1140
"threading module.");
1141
1142
#define _THREAD__MAKE_THREAD_HANDLE_METHODDEF    \
1143
    {"_make_thread_handle", (PyCFunction)_thread__make_thread_handle, METH_O, _thread__make_thread_handle__doc__},
1144
1145
PyDoc_STRVAR(_thread__get_main_thread_ident__doc__,
1146
"_get_main_thread_ident($module, /)\n"
1147
"--\n"
1148
"\n"
1149
"Internal only.\n"
1150
"\n"
1151
"Return a non-zero integer that uniquely identifies the main thread of\n"
1152
"the main interpreter.");
1153
1154
#define _THREAD__GET_MAIN_THREAD_IDENT_METHODDEF    \
1155
    {"_get_main_thread_ident", (PyCFunction)_thread__get_main_thread_ident, METH_NOARGS, _thread__get_main_thread_ident__doc__},
1156
1157
static PyObject *
1158
_thread__get_main_thread_ident_impl(PyObject *module);
1159
1160
static PyObject *
1161
_thread__get_main_thread_ident(PyObject *module, PyObject *Py_UNUSED(ignored))
1162
8
{
1163
8
    return _thread__get_main_thread_ident_impl(module);
1164
8
}
1165
1166
#if (defined(HAVE_PTHREAD_GETNAME_NP) || defined(HAVE_PTHREAD_GET_NAME_NP) || defined(MS_WINDOWS))
1167
1168
PyDoc_STRVAR(_thread__get_name__doc__,
1169
"_get_name($module, /)\n"
1170
"--\n"
1171
"\n"
1172
"Get the name of the current thread.");
1173
1174
#define _THREAD__GET_NAME_METHODDEF    \
1175
    {"_get_name", (PyCFunction)_thread__get_name, METH_NOARGS, _thread__get_name__doc__},
1176
1177
static PyObject *
1178
_thread__get_name_impl(PyObject *module);
1179
1180
static PyObject *
1181
_thread__get_name(PyObject *module, PyObject *Py_UNUSED(ignored))
1182
0
{
1183
0
    return _thread__get_name_impl(module);
1184
0
}
1185
1186
#endif /* (defined(HAVE_PTHREAD_GETNAME_NP) || defined(HAVE_PTHREAD_GET_NAME_NP) || defined(MS_WINDOWS)) */
1187
1188
#if (defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SET_NAME_NP) || defined(MS_WINDOWS))
1189
1190
PyDoc_STRVAR(_thread_set_name__doc__,
1191
"set_name($module, /, name)\n"
1192
"--\n"
1193
"\n"
1194
"Set the name of the current thread.");
1195
1196
#define _THREAD_SET_NAME_METHODDEF    \
1197
    {"set_name", _PyCFunction_CAST(_thread_set_name), METH_FASTCALL|METH_KEYWORDS, _thread_set_name__doc__},
1198
1199
static PyObject *
1200
_thread_set_name_impl(PyObject *module, PyObject *name_obj);
1201
1202
static PyObject *
1203
_thread_set_name(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1204
0
{
1205
0
    PyObject *return_value = NULL;
1206
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1207
1208
0
    #define NUM_KEYWORDS 1
1209
0
    static struct {
1210
0
        PyGC_Head _this_is_not_used;
1211
0
        PyObject_VAR_HEAD
1212
0
        Py_hash_t ob_hash;
1213
0
        PyObject *ob_item[NUM_KEYWORDS];
1214
0
    } _kwtuple = {
1215
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1216
0
        .ob_hash = -1,
1217
0
        .ob_item = { &_Py_ID(name), },
1218
0
    };
1219
0
    #undef NUM_KEYWORDS
1220
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1221
1222
    #else  // !Py_BUILD_CORE
1223
    #  define KWTUPLE NULL
1224
    #endif  // !Py_BUILD_CORE
1225
1226
0
    static const char * const _keywords[] = {"name", NULL};
1227
0
    static _PyArg_Parser _parser = {
1228
0
        .keywords = _keywords,
1229
0
        .fname = "set_name",
1230
0
        .kwtuple = KWTUPLE,
1231
0
    };
1232
0
    #undef KWTUPLE
1233
0
    PyObject *argsbuf[1];
1234
0
    PyObject *name_obj;
1235
1236
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1237
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1238
0
    if (!args) {
1239
0
        goto exit;
1240
0
    }
1241
0
    if (!PyUnicode_Check(args[0])) {
1242
0
        _PyArg_BadArgument("set_name", "argument 'name'", "str", args[0]);
1243
0
        goto exit;
1244
0
    }
1245
0
    name_obj = args[0];
1246
0
    return_value = _thread_set_name_impl(module, name_obj);
1247
1248
0
exit:
1249
0
    return return_value;
1250
0
}
1251
1252
#endif /* (defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SET_NAME_NP) || defined(MS_WINDOWS)) */
1253
1254
#ifndef _THREAD_LOCK__AT_FORK_REINIT_METHODDEF
1255
    #define _THREAD_LOCK__AT_FORK_REINIT_METHODDEF
1256
#endif /* !defined(_THREAD_LOCK__AT_FORK_REINIT_METHODDEF) */
1257
1258
#ifndef _THREAD_RLOCK__AT_FORK_REINIT_METHODDEF
1259
    #define _THREAD_RLOCK__AT_FORK_REINIT_METHODDEF
1260
#endif /* !defined(_THREAD_RLOCK__AT_FORK_REINIT_METHODDEF) */
1261
1262
#ifndef _THREAD_GET_NATIVE_ID_METHODDEF
1263
    #define _THREAD_GET_NATIVE_ID_METHODDEF
1264
#endif /* !defined(_THREAD_GET_NATIVE_ID_METHODDEF) */
1265
1266
#ifndef _THREAD__GET_NAME_METHODDEF
1267
    #define _THREAD__GET_NAME_METHODDEF
1268
#endif /* !defined(_THREAD__GET_NAME_METHODDEF) */
1269
1270
#ifndef _THREAD_SET_NAME_METHODDEF
1271
    #define _THREAD_SET_NAME_METHODDEF
1272
#endif /* !defined(_THREAD_SET_NAME_METHODDEF) */
1273
#define _THREAD__THREADHANDLE_IDENT_GETSETDEF {"ident", (getter)_thread__ThreadHandle_ident_get, (setter)NULL, NULL},
1274
1275
/*[clinic end generated code: output=3bfc76a318c6579d input=a9049054013a1b77]*/