1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS)
6
7 PyDoc_STRVAR(_multiprocessing_SemLock_acquire__doc__,
8 "acquire($self, /, block=True, timeout=None)\n"
9 "--\n"
10 "\n"
11 "Acquire the semaphore/lock.");
12
13 #define _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF \
14 {"acquire", _PyCFunction_CAST(_multiprocessing_SemLock_acquire), METH_FASTCALL|METH_KEYWORDS, _multiprocessing_SemLock_acquire__doc__},
15
16 static PyObject *
17 _multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking,
18 PyObject *timeout_obj);
19
20 static PyObject *
_multiprocessing_SemLock_acquire(SemLockObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)21 _multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
22 {
23 PyObject *return_value = NULL;
24 static const char * const _keywords[] = {"block", "timeout", NULL};
25 static _PyArg_Parser _parser = {NULL, _keywords, "acquire", 0};
26 PyObject *argsbuf[2];
27 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
28 int blocking = 1;
29 PyObject *timeout_obj = Py_None;
30
31 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
32 if (!args) {
33 goto exit;
34 }
35 if (!noptargs) {
36 goto skip_optional_pos;
37 }
38 if (args[0]) {
39 blocking = _PyLong_AsInt(args[0]);
40 if (blocking == -1 && PyErr_Occurred()) {
41 goto exit;
42 }
43 if (!--noptargs) {
44 goto skip_optional_pos;
45 }
46 }
47 timeout_obj = args[1];
48 skip_optional_pos:
49 return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj);
50
51 exit:
52 return return_value;
53 }
54
55 #endif /* defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) */
56
57 #if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS)
58
59 PyDoc_STRVAR(_multiprocessing_SemLock_release__doc__,
60 "release($self, /)\n"
61 "--\n"
62 "\n"
63 "Release the semaphore/lock.");
64
65 #define _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF \
66 {"release", (PyCFunction)_multiprocessing_SemLock_release, METH_NOARGS, _multiprocessing_SemLock_release__doc__},
67
68 static PyObject *
69 _multiprocessing_SemLock_release_impl(SemLockObject *self);
70
71 static PyObject *
_multiprocessing_SemLock_release(SemLockObject * self,PyObject * Py_UNUSED (ignored))72 _multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored))
73 {
74 return _multiprocessing_SemLock_release_impl(self);
75 }
76
77 #endif /* defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) */
78
79 #if defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS)
80
81 PyDoc_STRVAR(_multiprocessing_SemLock_acquire__doc__,
82 "acquire($self, /, block=True, timeout=None)\n"
83 "--\n"
84 "\n"
85 "Acquire the semaphore/lock.");
86
87 #define _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF \
88 {"acquire", _PyCFunction_CAST(_multiprocessing_SemLock_acquire), METH_FASTCALL|METH_KEYWORDS, _multiprocessing_SemLock_acquire__doc__},
89
90 static PyObject *
91 _multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking,
92 PyObject *timeout_obj);
93
94 static PyObject *
_multiprocessing_SemLock_acquire(SemLockObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)95 _multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
96 {
97 PyObject *return_value = NULL;
98 static const char * const _keywords[] = {"block", "timeout", NULL};
99 static _PyArg_Parser _parser = {NULL, _keywords, "acquire", 0};
100 PyObject *argsbuf[2];
101 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
102 int blocking = 1;
103 PyObject *timeout_obj = Py_None;
104
105 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
106 if (!args) {
107 goto exit;
108 }
109 if (!noptargs) {
110 goto skip_optional_pos;
111 }
112 if (args[0]) {
113 blocking = _PyLong_AsInt(args[0]);
114 if (blocking == -1 && PyErr_Occurred()) {
115 goto exit;
116 }
117 if (!--noptargs) {
118 goto skip_optional_pos;
119 }
120 }
121 timeout_obj = args[1];
122 skip_optional_pos:
123 return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj);
124
125 exit:
126 return return_value;
127 }
128
129 #endif /* defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) */
130
131 #if defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS)
132
133 PyDoc_STRVAR(_multiprocessing_SemLock_release__doc__,
134 "release($self, /)\n"
135 "--\n"
136 "\n"
137 "Release the semaphore/lock.");
138
139 #define _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF \
140 {"release", (PyCFunction)_multiprocessing_SemLock_release, METH_NOARGS, _multiprocessing_SemLock_release__doc__},
141
142 static PyObject *
143 _multiprocessing_SemLock_release_impl(SemLockObject *self);
144
145 static PyObject *
_multiprocessing_SemLock_release(SemLockObject * self,PyObject * Py_UNUSED (ignored))146 _multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored))
147 {
148 return _multiprocessing_SemLock_release_impl(self);
149 }
150
151 #endif /* defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) */
152
153 #if defined(HAVE_MP_SEMAPHORE)
154
155 static PyObject *
156 _multiprocessing_SemLock_impl(PyTypeObject *type, int kind, int value,
157 int maxvalue, const char *name, int unlink);
158
159 static PyObject *
_multiprocessing_SemLock(PyTypeObject * type,PyObject * args,PyObject * kwargs)160 _multiprocessing_SemLock(PyTypeObject *type, PyObject *args, PyObject *kwargs)
161 {
162 PyObject *return_value = NULL;
163 static const char * const _keywords[] = {"kind", "value", "maxvalue", "name", "unlink", NULL};
164 static _PyArg_Parser _parser = {NULL, _keywords, "SemLock", 0};
165 PyObject *argsbuf[5];
166 PyObject * const *fastargs;
167 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
168 int kind;
169 int value;
170 int maxvalue;
171 const char *name;
172 int unlink;
173
174 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 5, 5, 0, argsbuf);
175 if (!fastargs) {
176 goto exit;
177 }
178 kind = _PyLong_AsInt(fastargs[0]);
179 if (kind == -1 && PyErr_Occurred()) {
180 goto exit;
181 }
182 value = _PyLong_AsInt(fastargs[1]);
183 if (value == -1 && PyErr_Occurred()) {
184 goto exit;
185 }
186 maxvalue = _PyLong_AsInt(fastargs[2]);
187 if (maxvalue == -1 && PyErr_Occurred()) {
188 goto exit;
189 }
190 if (!PyUnicode_Check(fastargs[3])) {
191 _PyArg_BadArgument("SemLock", "argument 'name'", "str", fastargs[3]);
192 goto exit;
193 }
194 Py_ssize_t name_length;
195 name = PyUnicode_AsUTF8AndSize(fastargs[3], &name_length);
196 if (name == NULL) {
197 goto exit;
198 }
199 if (strlen(name) != (size_t)name_length) {
200 PyErr_SetString(PyExc_ValueError, "embedded null character");
201 goto exit;
202 }
203 unlink = _PyLong_AsInt(fastargs[4]);
204 if (unlink == -1 && PyErr_Occurred()) {
205 goto exit;
206 }
207 return_value = _multiprocessing_SemLock_impl(type, kind, value, maxvalue, name, unlink);
208
209 exit:
210 return return_value;
211 }
212
213 #endif /* defined(HAVE_MP_SEMAPHORE) */
214
215 #if defined(HAVE_MP_SEMAPHORE)
216
217 PyDoc_STRVAR(_multiprocessing_SemLock__rebuild__doc__,
218 "_rebuild($type, handle, kind, maxvalue, name, /)\n"
219 "--\n"
220 "\n");
221
222 #define _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF \
223 {"_rebuild", _PyCFunction_CAST(_multiprocessing_SemLock__rebuild), METH_FASTCALL|METH_CLASS, _multiprocessing_SemLock__rebuild__doc__},
224
225 static PyObject *
226 _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle,
227 int kind, int maxvalue,
228 const char *name);
229
230 static PyObject *
_multiprocessing_SemLock__rebuild(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs)231 _multiprocessing_SemLock__rebuild(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
232 {
233 PyObject *return_value = NULL;
234 SEM_HANDLE handle;
235 int kind;
236 int maxvalue;
237 const char *name;
238
239 if (!_PyArg_ParseStack(args, nargs, ""F_SEM_HANDLE"iiz:_rebuild",
240 &handle, &kind, &maxvalue, &name)) {
241 goto exit;
242 }
243 return_value = _multiprocessing_SemLock__rebuild_impl(type, handle, kind, maxvalue, name);
244
245 exit:
246 return return_value;
247 }
248
249 #endif /* defined(HAVE_MP_SEMAPHORE) */
250
251 #if defined(HAVE_MP_SEMAPHORE)
252
253 PyDoc_STRVAR(_multiprocessing_SemLock__count__doc__,
254 "_count($self, /)\n"
255 "--\n"
256 "\n"
257 "Num of `acquire()`s minus num of `release()`s for this process.");
258
259 #define _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF \
260 {"_count", (PyCFunction)_multiprocessing_SemLock__count, METH_NOARGS, _multiprocessing_SemLock__count__doc__},
261
262 static PyObject *
263 _multiprocessing_SemLock__count_impl(SemLockObject *self);
264
265 static PyObject *
_multiprocessing_SemLock__count(SemLockObject * self,PyObject * Py_UNUSED (ignored))266 _multiprocessing_SemLock__count(SemLockObject *self, PyObject *Py_UNUSED(ignored))
267 {
268 return _multiprocessing_SemLock__count_impl(self);
269 }
270
271 #endif /* defined(HAVE_MP_SEMAPHORE) */
272
273 #if defined(HAVE_MP_SEMAPHORE)
274
275 PyDoc_STRVAR(_multiprocessing_SemLock__is_mine__doc__,
276 "_is_mine($self, /)\n"
277 "--\n"
278 "\n"
279 "Whether the lock is owned by this thread.");
280
281 #define _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF \
282 {"_is_mine", (PyCFunction)_multiprocessing_SemLock__is_mine, METH_NOARGS, _multiprocessing_SemLock__is_mine__doc__},
283
284 static PyObject *
285 _multiprocessing_SemLock__is_mine_impl(SemLockObject *self);
286
287 static PyObject *
_multiprocessing_SemLock__is_mine(SemLockObject * self,PyObject * Py_UNUSED (ignored))288 _multiprocessing_SemLock__is_mine(SemLockObject *self, PyObject *Py_UNUSED(ignored))
289 {
290 return _multiprocessing_SemLock__is_mine_impl(self);
291 }
292
293 #endif /* defined(HAVE_MP_SEMAPHORE) */
294
295 #if defined(HAVE_MP_SEMAPHORE)
296
297 PyDoc_STRVAR(_multiprocessing_SemLock__get_value__doc__,
298 "_get_value($self, /)\n"
299 "--\n"
300 "\n"
301 "Get the value of the semaphore.");
302
303 #define _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF \
304 {"_get_value", (PyCFunction)_multiprocessing_SemLock__get_value, METH_NOARGS, _multiprocessing_SemLock__get_value__doc__},
305
306 static PyObject *
307 _multiprocessing_SemLock__get_value_impl(SemLockObject *self);
308
309 static PyObject *
_multiprocessing_SemLock__get_value(SemLockObject * self,PyObject * Py_UNUSED (ignored))310 _multiprocessing_SemLock__get_value(SemLockObject *self, PyObject *Py_UNUSED(ignored))
311 {
312 return _multiprocessing_SemLock__get_value_impl(self);
313 }
314
315 #endif /* defined(HAVE_MP_SEMAPHORE) */
316
317 #if defined(HAVE_MP_SEMAPHORE)
318
319 PyDoc_STRVAR(_multiprocessing_SemLock__is_zero__doc__,
320 "_is_zero($self, /)\n"
321 "--\n"
322 "\n"
323 "Return whether semaphore has value zero.");
324
325 #define _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF \
326 {"_is_zero", (PyCFunction)_multiprocessing_SemLock__is_zero, METH_NOARGS, _multiprocessing_SemLock__is_zero__doc__},
327
328 static PyObject *
329 _multiprocessing_SemLock__is_zero_impl(SemLockObject *self);
330
331 static PyObject *
_multiprocessing_SemLock__is_zero(SemLockObject * self,PyObject * Py_UNUSED (ignored))332 _multiprocessing_SemLock__is_zero(SemLockObject *self, PyObject *Py_UNUSED(ignored))
333 {
334 return _multiprocessing_SemLock__is_zero_impl(self);
335 }
336
337 #endif /* defined(HAVE_MP_SEMAPHORE) */
338
339 #if defined(HAVE_MP_SEMAPHORE)
340
341 PyDoc_STRVAR(_multiprocessing_SemLock__after_fork__doc__,
342 "_after_fork($self, /)\n"
343 "--\n"
344 "\n"
345 "Rezero the net acquisition count after fork().");
346
347 #define _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF \
348 {"_after_fork", (PyCFunction)_multiprocessing_SemLock__after_fork, METH_NOARGS, _multiprocessing_SemLock__after_fork__doc__},
349
350 static PyObject *
351 _multiprocessing_SemLock__after_fork_impl(SemLockObject *self);
352
353 static PyObject *
_multiprocessing_SemLock__after_fork(SemLockObject * self,PyObject * Py_UNUSED (ignored))354 _multiprocessing_SemLock__after_fork(SemLockObject *self, PyObject *Py_UNUSED(ignored))
355 {
356 return _multiprocessing_SemLock__after_fork_impl(self);
357 }
358
359 #endif /* defined(HAVE_MP_SEMAPHORE) */
360
361 #if defined(HAVE_MP_SEMAPHORE)
362
363 PyDoc_STRVAR(_multiprocessing_SemLock___enter____doc__,
364 "__enter__($self, /)\n"
365 "--\n"
366 "\n"
367 "Enter the semaphore/lock.");
368
369 #define _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF \
370 {"__enter__", (PyCFunction)_multiprocessing_SemLock___enter__, METH_NOARGS, _multiprocessing_SemLock___enter____doc__},
371
372 static PyObject *
373 _multiprocessing_SemLock___enter___impl(SemLockObject *self);
374
375 static PyObject *
_multiprocessing_SemLock___enter__(SemLockObject * self,PyObject * Py_UNUSED (ignored))376 _multiprocessing_SemLock___enter__(SemLockObject *self, PyObject *Py_UNUSED(ignored))
377 {
378 return _multiprocessing_SemLock___enter___impl(self);
379 }
380
381 #endif /* defined(HAVE_MP_SEMAPHORE) */
382
383 #if defined(HAVE_MP_SEMAPHORE)
384
385 PyDoc_STRVAR(_multiprocessing_SemLock___exit____doc__,
386 "__exit__($self, exc_type=None, exc_value=None, exc_tb=None, /)\n"
387 "--\n"
388 "\n"
389 "Exit the semaphore/lock.");
390
391 #define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF \
392 {"__exit__", _PyCFunction_CAST(_multiprocessing_SemLock___exit__), METH_FASTCALL, _multiprocessing_SemLock___exit____doc__},
393
394 static PyObject *
395 _multiprocessing_SemLock___exit___impl(SemLockObject *self,
396 PyObject *exc_type,
397 PyObject *exc_value, PyObject *exc_tb);
398
399 static PyObject *
_multiprocessing_SemLock___exit__(SemLockObject * self,PyObject * const * args,Py_ssize_t nargs)400 _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs)
401 {
402 PyObject *return_value = NULL;
403 PyObject *exc_type = Py_None;
404 PyObject *exc_value = Py_None;
405 PyObject *exc_tb = Py_None;
406
407 if (!_PyArg_CheckPositional("__exit__", nargs, 0, 3)) {
408 goto exit;
409 }
410 if (nargs < 1) {
411 goto skip_optional;
412 }
413 exc_type = args[0];
414 if (nargs < 2) {
415 goto skip_optional;
416 }
417 exc_value = args[1];
418 if (nargs < 3) {
419 goto skip_optional;
420 }
421 exc_tb = args[2];
422 skip_optional:
423 return_value = _multiprocessing_SemLock___exit___impl(self, exc_type, exc_value, exc_tb);
424
425 exit:
426 return return_value;
427 }
428
429 #endif /* defined(HAVE_MP_SEMAPHORE) */
430
431 #ifndef _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF
432 #define _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF
433 #endif /* !defined(_MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF) */
434
435 #ifndef _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF
436 #define _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF
437 #endif /* !defined(_MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF) */
438
439 #ifndef _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF
440 #define _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF
441 #endif /* !defined(_MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF) */
442
443 #ifndef _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF
444 #define _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF
445 #endif /* !defined(_MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF) */
446
447 #ifndef _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF
448 #define _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF
449 #endif /* !defined(_MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF) */
450
451 #ifndef _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF
452 #define _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF
453 #endif /* !defined(_MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF) */
454
455 #ifndef _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF
456 #define _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF
457 #endif /* !defined(_MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF) */
458
459 #ifndef _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF
460 #define _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF
461 #endif /* !defined(_MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF) */
462
463 #ifndef _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF
464 #define _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF
465 #endif /* !defined(_MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF) */
466
467 #ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
468 #define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
469 #endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */
470 /*[clinic end generated code: output=64ba32544811c9e6 input=a9049054013a1b77]*/
471