1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if 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)(void(*)(void))_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(MS_WINDOWS) */
56
57 #if 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(MS_WINDOWS) */
78
79 #if !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)(void(*)(void))_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(MS_WINDOWS) */
130
131 #if !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(MS_WINDOWS) */
152
153 static PyObject *
154 _multiprocessing_SemLock_impl(PyTypeObject *type, int kind, int value,
155 int maxvalue, const char *name, int unlink);
156
157 static PyObject *
_multiprocessing_SemLock(PyTypeObject * type,PyObject * args,PyObject * kwargs)158 _multiprocessing_SemLock(PyTypeObject *type, PyObject *args, PyObject *kwargs)
159 {
160 PyObject *return_value = NULL;
161 static const char * const _keywords[] = {"kind", "value", "maxvalue", "name", "unlink", NULL};
162 static _PyArg_Parser _parser = {NULL, _keywords, "SemLock", 0};
163 PyObject *argsbuf[5];
164 PyObject * const *fastargs;
165 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
166 int kind;
167 int value;
168 int maxvalue;
169 const char *name;
170 int unlink;
171
172 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 5, 5, 0, argsbuf);
173 if (!fastargs) {
174 goto exit;
175 }
176 kind = _PyLong_AsInt(fastargs[0]);
177 if (kind == -1 && PyErr_Occurred()) {
178 goto exit;
179 }
180 value = _PyLong_AsInt(fastargs[1]);
181 if (value == -1 && PyErr_Occurred()) {
182 goto exit;
183 }
184 maxvalue = _PyLong_AsInt(fastargs[2]);
185 if (maxvalue == -1 && PyErr_Occurred()) {
186 goto exit;
187 }
188 if (!PyUnicode_Check(fastargs[3])) {
189 _PyArg_BadArgument("SemLock", "argument 'name'", "str", fastargs[3]);
190 goto exit;
191 }
192 Py_ssize_t name_length;
193 name = PyUnicode_AsUTF8AndSize(fastargs[3], &name_length);
194 if (name == NULL) {
195 goto exit;
196 }
197 if (strlen(name) != (size_t)name_length) {
198 PyErr_SetString(PyExc_ValueError, "embedded null character");
199 goto exit;
200 }
201 unlink = _PyLong_AsInt(fastargs[4]);
202 if (unlink == -1 && PyErr_Occurred()) {
203 goto exit;
204 }
205 return_value = _multiprocessing_SemLock_impl(type, kind, value, maxvalue, name, unlink);
206
207 exit:
208 return return_value;
209 }
210
211 PyDoc_STRVAR(_multiprocessing_SemLock__rebuild__doc__,
212 "_rebuild($type, handle, kind, maxvalue, name, /)\n"
213 "--\n"
214 "\n");
215
216 #define _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF \
217 {"_rebuild", (PyCFunction)(void(*)(void))_multiprocessing_SemLock__rebuild, METH_FASTCALL|METH_CLASS, _multiprocessing_SemLock__rebuild__doc__},
218
219 static PyObject *
220 _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle,
221 int kind, int maxvalue,
222 const char *name);
223
224 static PyObject *
_multiprocessing_SemLock__rebuild(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs)225 _multiprocessing_SemLock__rebuild(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
226 {
227 PyObject *return_value = NULL;
228 SEM_HANDLE handle;
229 int kind;
230 int maxvalue;
231 const char *name;
232
233 if (!_PyArg_ParseStack(args, nargs, ""F_SEM_HANDLE"iiz:_rebuild",
234 &handle, &kind, &maxvalue, &name)) {
235 goto exit;
236 }
237 return_value = _multiprocessing_SemLock__rebuild_impl(type, handle, kind, maxvalue, name);
238
239 exit:
240 return return_value;
241 }
242
243 PyDoc_STRVAR(_multiprocessing_SemLock__count__doc__,
244 "_count($self, /)\n"
245 "--\n"
246 "\n"
247 "Num of `acquire()`s minus num of `release()`s for this process.");
248
249 #define _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF \
250 {"_count", (PyCFunction)_multiprocessing_SemLock__count, METH_NOARGS, _multiprocessing_SemLock__count__doc__},
251
252 static PyObject *
253 _multiprocessing_SemLock__count_impl(SemLockObject *self);
254
255 static PyObject *
_multiprocessing_SemLock__count(SemLockObject * self,PyObject * Py_UNUSED (ignored))256 _multiprocessing_SemLock__count(SemLockObject *self, PyObject *Py_UNUSED(ignored))
257 {
258 return _multiprocessing_SemLock__count_impl(self);
259 }
260
261 PyDoc_STRVAR(_multiprocessing_SemLock__is_mine__doc__,
262 "_is_mine($self, /)\n"
263 "--\n"
264 "\n"
265 "Whether the lock is owned by this thread.");
266
267 #define _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF \
268 {"_is_mine", (PyCFunction)_multiprocessing_SemLock__is_mine, METH_NOARGS, _multiprocessing_SemLock__is_mine__doc__},
269
270 static PyObject *
271 _multiprocessing_SemLock__is_mine_impl(SemLockObject *self);
272
273 static PyObject *
_multiprocessing_SemLock__is_mine(SemLockObject * self,PyObject * Py_UNUSED (ignored))274 _multiprocessing_SemLock__is_mine(SemLockObject *self, PyObject *Py_UNUSED(ignored))
275 {
276 return _multiprocessing_SemLock__is_mine_impl(self);
277 }
278
279 PyDoc_STRVAR(_multiprocessing_SemLock__get_value__doc__,
280 "_get_value($self, /)\n"
281 "--\n"
282 "\n"
283 "Get the value of the semaphore.");
284
285 #define _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF \
286 {"_get_value", (PyCFunction)_multiprocessing_SemLock__get_value, METH_NOARGS, _multiprocessing_SemLock__get_value__doc__},
287
288 static PyObject *
289 _multiprocessing_SemLock__get_value_impl(SemLockObject *self);
290
291 static PyObject *
_multiprocessing_SemLock__get_value(SemLockObject * self,PyObject * Py_UNUSED (ignored))292 _multiprocessing_SemLock__get_value(SemLockObject *self, PyObject *Py_UNUSED(ignored))
293 {
294 return _multiprocessing_SemLock__get_value_impl(self);
295 }
296
297 PyDoc_STRVAR(_multiprocessing_SemLock__is_zero__doc__,
298 "_is_zero($self, /)\n"
299 "--\n"
300 "\n"
301 "Return whether semaphore has value zero.");
302
303 #define _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF \
304 {"_is_zero", (PyCFunction)_multiprocessing_SemLock__is_zero, METH_NOARGS, _multiprocessing_SemLock__is_zero__doc__},
305
306 static PyObject *
307 _multiprocessing_SemLock__is_zero_impl(SemLockObject *self);
308
309 static PyObject *
_multiprocessing_SemLock__is_zero(SemLockObject * self,PyObject * Py_UNUSED (ignored))310 _multiprocessing_SemLock__is_zero(SemLockObject *self, PyObject *Py_UNUSED(ignored))
311 {
312 return _multiprocessing_SemLock__is_zero_impl(self);
313 }
314
315 PyDoc_STRVAR(_multiprocessing_SemLock__after_fork__doc__,
316 "_after_fork($self, /)\n"
317 "--\n"
318 "\n"
319 "Rezero the net acquisition count after fork().");
320
321 #define _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF \
322 {"_after_fork", (PyCFunction)_multiprocessing_SemLock__after_fork, METH_NOARGS, _multiprocessing_SemLock__after_fork__doc__},
323
324 static PyObject *
325 _multiprocessing_SemLock__after_fork_impl(SemLockObject *self);
326
327 static PyObject *
_multiprocessing_SemLock__after_fork(SemLockObject * self,PyObject * Py_UNUSED (ignored))328 _multiprocessing_SemLock__after_fork(SemLockObject *self, PyObject *Py_UNUSED(ignored))
329 {
330 return _multiprocessing_SemLock__after_fork_impl(self);
331 }
332
333 PyDoc_STRVAR(_multiprocessing_SemLock___enter____doc__,
334 "__enter__($self, /)\n"
335 "--\n"
336 "\n"
337 "Enter the semaphore/lock.");
338
339 #define _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF \
340 {"__enter__", (PyCFunction)_multiprocessing_SemLock___enter__, METH_NOARGS, _multiprocessing_SemLock___enter____doc__},
341
342 static PyObject *
343 _multiprocessing_SemLock___enter___impl(SemLockObject *self);
344
345 static PyObject *
_multiprocessing_SemLock___enter__(SemLockObject * self,PyObject * Py_UNUSED (ignored))346 _multiprocessing_SemLock___enter__(SemLockObject *self, PyObject *Py_UNUSED(ignored))
347 {
348 return _multiprocessing_SemLock___enter___impl(self);
349 }
350
351 PyDoc_STRVAR(_multiprocessing_SemLock___exit____doc__,
352 "__exit__($self, exc_type=None, exc_value=None, exc_tb=None, /)\n"
353 "--\n"
354 "\n"
355 "Exit the semaphore/lock.");
356
357 #define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF \
358 {"__exit__", (PyCFunction)(void(*)(void))_multiprocessing_SemLock___exit__, METH_FASTCALL, _multiprocessing_SemLock___exit____doc__},
359
360 static PyObject *
361 _multiprocessing_SemLock___exit___impl(SemLockObject *self,
362 PyObject *exc_type,
363 PyObject *exc_value, PyObject *exc_tb);
364
365 static PyObject *
_multiprocessing_SemLock___exit__(SemLockObject * self,PyObject * const * args,Py_ssize_t nargs)366 _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs)
367 {
368 PyObject *return_value = NULL;
369 PyObject *exc_type = Py_None;
370 PyObject *exc_value = Py_None;
371 PyObject *exc_tb = Py_None;
372
373 if (!_PyArg_CheckPositional("__exit__", nargs, 0, 3)) {
374 goto exit;
375 }
376 if (nargs < 1) {
377 goto skip_optional;
378 }
379 exc_type = args[0];
380 if (nargs < 2) {
381 goto skip_optional;
382 }
383 exc_value = args[1];
384 if (nargs < 3) {
385 goto skip_optional;
386 }
387 exc_tb = args[2];
388 skip_optional:
389 return_value = _multiprocessing_SemLock___exit___impl(self, exc_type, exc_value, exc_tb);
390
391 exit:
392 return return_value;
393 }
394
395 #ifndef _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF
396 #define _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF
397 #endif /* !defined(_MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF) */
398
399 #ifndef _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF
400 #define _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF
401 #endif /* !defined(_MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF) */
402 /*[clinic end generated code: output=e7fd938150601fe5 input=a9049054013a1b77]*/
403