Path: blob/main/Modules/_multiprocessing/clinic/semaphore.c.h
12 views
/*[clinic input]1preserve2[clinic start generated code]*/34#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)5# include "pycore_gc.h" // PyGC_Head6# include "pycore_runtime.h" // _Py_ID()7#endif8910#if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS)1112PyDoc_STRVAR(_multiprocessing_SemLock_acquire__doc__,13"acquire($self, /, block=True, timeout=None)\n"14"--\n"15"\n"16"Acquire the semaphore/lock.");1718#define _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF \19{"acquire", _PyCFunction_CAST(_multiprocessing_SemLock_acquire), METH_FASTCALL|METH_KEYWORDS, _multiprocessing_SemLock_acquire__doc__},2021static PyObject *22_multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking,23PyObject *timeout_obj);2425static PyObject *26_multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)27{28PyObject *return_value = NULL;29#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)3031#define NUM_KEYWORDS 232static struct {33PyGC_Head _this_is_not_used;34PyObject_VAR_HEAD35PyObject *ob_item[NUM_KEYWORDS];36} _kwtuple = {37.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)38.ob_item = { &_Py_ID(block), &_Py_ID(timeout), },39};40#undef NUM_KEYWORDS41#define KWTUPLE (&_kwtuple.ob_base.ob_base)4243#else // !Py_BUILD_CORE44# define KWTUPLE NULL45#endif // !Py_BUILD_CORE4647static const char * const _keywords[] = {"block", "timeout", NULL};48static _PyArg_Parser _parser = {49.keywords = _keywords,50.fname = "acquire",51.kwtuple = KWTUPLE,52};53#undef KWTUPLE54PyObject *argsbuf[2];55Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;56int blocking = 1;57PyObject *timeout_obj = Py_None;5859args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);60if (!args) {61goto exit;62}63if (!noptargs) {64goto skip_optional_pos;65}66if (args[0]) {67blocking = PyObject_IsTrue(args[0]);68if (blocking < 0) {69goto exit;70}71if (!--noptargs) {72goto skip_optional_pos;73}74}75timeout_obj = args[1];76skip_optional_pos:77return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj);7879exit:80return return_value;81}8283#endif /* defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) */8485#if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS)8687PyDoc_STRVAR(_multiprocessing_SemLock_release__doc__,88"release($self, /)\n"89"--\n"90"\n"91"Release the semaphore/lock.");9293#define _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF \94{"release", (PyCFunction)_multiprocessing_SemLock_release, METH_NOARGS, _multiprocessing_SemLock_release__doc__},9596static PyObject *97_multiprocessing_SemLock_release_impl(SemLockObject *self);9899static PyObject *100_multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored))101{102return _multiprocessing_SemLock_release_impl(self);103}104105#endif /* defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS) */106107#if defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS)108109PyDoc_STRVAR(_multiprocessing_SemLock_acquire__doc__,110"acquire($self, /, block=True, timeout=None)\n"111"--\n"112"\n"113"Acquire the semaphore/lock.");114115#define _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF \116{"acquire", _PyCFunction_CAST(_multiprocessing_SemLock_acquire), METH_FASTCALL|METH_KEYWORDS, _multiprocessing_SemLock_acquire__doc__},117118static PyObject *119_multiprocessing_SemLock_acquire_impl(SemLockObject *self, int blocking,120PyObject *timeout_obj);121122static PyObject *123_multiprocessing_SemLock_acquire(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)124{125PyObject *return_value = NULL;126#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)127128#define NUM_KEYWORDS 2129static struct {130PyGC_Head _this_is_not_used;131PyObject_VAR_HEAD132PyObject *ob_item[NUM_KEYWORDS];133} _kwtuple = {134.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)135.ob_item = { &_Py_ID(block), &_Py_ID(timeout), },136};137#undef NUM_KEYWORDS138#define KWTUPLE (&_kwtuple.ob_base.ob_base)139140#else // !Py_BUILD_CORE141# define KWTUPLE NULL142#endif // !Py_BUILD_CORE143144static const char * const _keywords[] = {"block", "timeout", NULL};145static _PyArg_Parser _parser = {146.keywords = _keywords,147.fname = "acquire",148.kwtuple = KWTUPLE,149};150#undef KWTUPLE151PyObject *argsbuf[2];152Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;153int blocking = 1;154PyObject *timeout_obj = Py_None;155156args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);157if (!args) {158goto exit;159}160if (!noptargs) {161goto skip_optional_pos;162}163if (args[0]) {164blocking = PyObject_IsTrue(args[0]);165if (blocking < 0) {166goto exit;167}168if (!--noptargs) {169goto skip_optional_pos;170}171}172timeout_obj = args[1];173skip_optional_pos:174return_value = _multiprocessing_SemLock_acquire_impl(self, blocking, timeout_obj);175176exit:177return return_value;178}179180#endif /* defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) */181182#if defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS)183184PyDoc_STRVAR(_multiprocessing_SemLock_release__doc__,185"release($self, /)\n"186"--\n"187"\n"188"Release the semaphore/lock.");189190#define _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF \191{"release", (PyCFunction)_multiprocessing_SemLock_release, METH_NOARGS, _multiprocessing_SemLock_release__doc__},192193static PyObject *194_multiprocessing_SemLock_release_impl(SemLockObject *self);195196static PyObject *197_multiprocessing_SemLock_release(SemLockObject *self, PyObject *Py_UNUSED(ignored))198{199return _multiprocessing_SemLock_release_impl(self);200}201202#endif /* defined(HAVE_MP_SEMAPHORE) && !defined(MS_WINDOWS) */203204#if defined(HAVE_MP_SEMAPHORE)205206static PyObject *207_multiprocessing_SemLock_impl(PyTypeObject *type, int kind, int value,208int maxvalue, const char *name, int unlink);209210static PyObject *211_multiprocessing_SemLock(PyTypeObject *type, PyObject *args, PyObject *kwargs)212{213PyObject *return_value = NULL;214#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)215216#define NUM_KEYWORDS 5217static struct {218PyGC_Head _this_is_not_used;219PyObject_VAR_HEAD220PyObject *ob_item[NUM_KEYWORDS];221} _kwtuple = {222.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)223.ob_item = { &_Py_ID(kind), &_Py_ID(value), &_Py_ID(maxvalue), &_Py_ID(name), &_Py_ID(unlink), },224};225#undef NUM_KEYWORDS226#define KWTUPLE (&_kwtuple.ob_base.ob_base)227228#else // !Py_BUILD_CORE229# define KWTUPLE NULL230#endif // !Py_BUILD_CORE231232static const char * const _keywords[] = {"kind", "value", "maxvalue", "name", "unlink", NULL};233static _PyArg_Parser _parser = {234.keywords = _keywords,235.fname = "SemLock",236.kwtuple = KWTUPLE,237};238#undef KWTUPLE239PyObject *argsbuf[5];240PyObject * const *fastargs;241Py_ssize_t nargs = PyTuple_GET_SIZE(args);242int kind;243int value;244int maxvalue;245const char *name;246int unlink;247248fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 5, 5, 0, argsbuf);249if (!fastargs) {250goto exit;251}252kind = _PyLong_AsInt(fastargs[0]);253if (kind == -1 && PyErr_Occurred()) {254goto exit;255}256value = _PyLong_AsInt(fastargs[1]);257if (value == -1 && PyErr_Occurred()) {258goto exit;259}260maxvalue = _PyLong_AsInt(fastargs[2]);261if (maxvalue == -1 && PyErr_Occurred()) {262goto exit;263}264if (!PyUnicode_Check(fastargs[3])) {265_PyArg_BadArgument("SemLock", "argument 'name'", "str", fastargs[3]);266goto exit;267}268Py_ssize_t name_length;269name = PyUnicode_AsUTF8AndSize(fastargs[3], &name_length);270if (name == NULL) {271goto exit;272}273if (strlen(name) != (size_t)name_length) {274PyErr_SetString(PyExc_ValueError, "embedded null character");275goto exit;276}277unlink = PyObject_IsTrue(fastargs[4]);278if (unlink < 0) {279goto exit;280}281return_value = _multiprocessing_SemLock_impl(type, kind, value, maxvalue, name, unlink);282283exit:284return return_value;285}286287#endif /* defined(HAVE_MP_SEMAPHORE) */288289#if defined(HAVE_MP_SEMAPHORE)290291PyDoc_STRVAR(_multiprocessing_SemLock__rebuild__doc__,292"_rebuild($type, handle, kind, maxvalue, name, /)\n"293"--\n"294"\n");295296#define _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF \297{"_rebuild", _PyCFunction_CAST(_multiprocessing_SemLock__rebuild), METH_FASTCALL|METH_CLASS, _multiprocessing_SemLock__rebuild__doc__},298299static PyObject *300_multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle,301int kind, int maxvalue,302const char *name);303304static PyObject *305_multiprocessing_SemLock__rebuild(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)306{307PyObject *return_value = NULL;308SEM_HANDLE handle;309int kind;310int maxvalue;311const char *name;312313if (!_PyArg_ParseStack(args, nargs, ""F_SEM_HANDLE"iiz:_rebuild",314&handle, &kind, &maxvalue, &name)) {315goto exit;316}317return_value = _multiprocessing_SemLock__rebuild_impl(type, handle, kind, maxvalue, name);318319exit:320return return_value;321}322323#endif /* defined(HAVE_MP_SEMAPHORE) */324325#if defined(HAVE_MP_SEMAPHORE)326327PyDoc_STRVAR(_multiprocessing_SemLock__count__doc__,328"_count($self, /)\n"329"--\n"330"\n"331"Num of `acquire()`s minus num of `release()`s for this process.");332333#define _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF \334{"_count", (PyCFunction)_multiprocessing_SemLock__count, METH_NOARGS, _multiprocessing_SemLock__count__doc__},335336static PyObject *337_multiprocessing_SemLock__count_impl(SemLockObject *self);338339static PyObject *340_multiprocessing_SemLock__count(SemLockObject *self, PyObject *Py_UNUSED(ignored))341{342return _multiprocessing_SemLock__count_impl(self);343}344345#endif /* defined(HAVE_MP_SEMAPHORE) */346347#if defined(HAVE_MP_SEMAPHORE)348349PyDoc_STRVAR(_multiprocessing_SemLock__is_mine__doc__,350"_is_mine($self, /)\n"351"--\n"352"\n"353"Whether the lock is owned by this thread.");354355#define _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF \356{"_is_mine", (PyCFunction)_multiprocessing_SemLock__is_mine, METH_NOARGS, _multiprocessing_SemLock__is_mine__doc__},357358static PyObject *359_multiprocessing_SemLock__is_mine_impl(SemLockObject *self);360361static PyObject *362_multiprocessing_SemLock__is_mine(SemLockObject *self, PyObject *Py_UNUSED(ignored))363{364return _multiprocessing_SemLock__is_mine_impl(self);365}366367#endif /* defined(HAVE_MP_SEMAPHORE) */368369#if defined(HAVE_MP_SEMAPHORE)370371PyDoc_STRVAR(_multiprocessing_SemLock__get_value__doc__,372"_get_value($self, /)\n"373"--\n"374"\n"375"Get the value of the semaphore.");376377#define _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF \378{"_get_value", (PyCFunction)_multiprocessing_SemLock__get_value, METH_NOARGS, _multiprocessing_SemLock__get_value__doc__},379380static PyObject *381_multiprocessing_SemLock__get_value_impl(SemLockObject *self);382383static PyObject *384_multiprocessing_SemLock__get_value(SemLockObject *self, PyObject *Py_UNUSED(ignored))385{386return _multiprocessing_SemLock__get_value_impl(self);387}388389#endif /* defined(HAVE_MP_SEMAPHORE) */390391#if defined(HAVE_MP_SEMAPHORE)392393PyDoc_STRVAR(_multiprocessing_SemLock__is_zero__doc__,394"_is_zero($self, /)\n"395"--\n"396"\n"397"Return whether semaphore has value zero.");398399#define _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF \400{"_is_zero", (PyCFunction)_multiprocessing_SemLock__is_zero, METH_NOARGS, _multiprocessing_SemLock__is_zero__doc__},401402static PyObject *403_multiprocessing_SemLock__is_zero_impl(SemLockObject *self);404405static PyObject *406_multiprocessing_SemLock__is_zero(SemLockObject *self, PyObject *Py_UNUSED(ignored))407{408return _multiprocessing_SemLock__is_zero_impl(self);409}410411#endif /* defined(HAVE_MP_SEMAPHORE) */412413#if defined(HAVE_MP_SEMAPHORE)414415PyDoc_STRVAR(_multiprocessing_SemLock__after_fork__doc__,416"_after_fork($self, /)\n"417"--\n"418"\n"419"Rezero the net acquisition count after fork().");420421#define _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF \422{"_after_fork", (PyCFunction)_multiprocessing_SemLock__after_fork, METH_NOARGS, _multiprocessing_SemLock__after_fork__doc__},423424static PyObject *425_multiprocessing_SemLock__after_fork_impl(SemLockObject *self);426427static PyObject *428_multiprocessing_SemLock__after_fork(SemLockObject *self, PyObject *Py_UNUSED(ignored))429{430return _multiprocessing_SemLock__after_fork_impl(self);431}432433#endif /* defined(HAVE_MP_SEMAPHORE) */434435#if defined(HAVE_MP_SEMAPHORE)436437PyDoc_STRVAR(_multiprocessing_SemLock___enter____doc__,438"__enter__($self, /)\n"439"--\n"440"\n"441"Enter the semaphore/lock.");442443#define _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF \444{"__enter__", (PyCFunction)_multiprocessing_SemLock___enter__, METH_NOARGS, _multiprocessing_SemLock___enter____doc__},445446static PyObject *447_multiprocessing_SemLock___enter___impl(SemLockObject *self);448449static PyObject *450_multiprocessing_SemLock___enter__(SemLockObject *self, PyObject *Py_UNUSED(ignored))451{452return _multiprocessing_SemLock___enter___impl(self);453}454455#endif /* defined(HAVE_MP_SEMAPHORE) */456457#if defined(HAVE_MP_SEMAPHORE)458459PyDoc_STRVAR(_multiprocessing_SemLock___exit____doc__,460"__exit__($self, exc_type=None, exc_value=None, exc_tb=None, /)\n"461"--\n"462"\n"463"Exit the semaphore/lock.");464465#define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF \466{"__exit__", _PyCFunction_CAST(_multiprocessing_SemLock___exit__), METH_FASTCALL, _multiprocessing_SemLock___exit____doc__},467468static PyObject *469_multiprocessing_SemLock___exit___impl(SemLockObject *self,470PyObject *exc_type,471PyObject *exc_value, PyObject *exc_tb);472473static PyObject *474_multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py_ssize_t nargs)475{476PyObject *return_value = NULL;477PyObject *exc_type = Py_None;478PyObject *exc_value = Py_None;479PyObject *exc_tb = Py_None;480481if (!_PyArg_CheckPositional("__exit__", nargs, 0, 3)) {482goto exit;483}484if (nargs < 1) {485goto skip_optional;486}487exc_type = args[0];488if (nargs < 2) {489goto skip_optional;490}491exc_value = args[1];492if (nargs < 3) {493goto skip_optional;494}495exc_tb = args[2];496skip_optional:497return_value = _multiprocessing_SemLock___exit___impl(self, exc_type, exc_value, exc_tb);498499exit:500return return_value;501}502503#endif /* defined(HAVE_MP_SEMAPHORE) */504505#ifndef _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF506#define _MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF507#endif /* !defined(_MULTIPROCESSING_SEMLOCK_ACQUIRE_METHODDEF) */508509#ifndef _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF510#define _MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF511#endif /* !defined(_MULTIPROCESSING_SEMLOCK_RELEASE_METHODDEF) */512513#ifndef _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF514#define _MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF515#endif /* !defined(_MULTIPROCESSING_SEMLOCK__REBUILD_METHODDEF) */516517#ifndef _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF518#define _MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF519#endif /* !defined(_MULTIPROCESSING_SEMLOCK__COUNT_METHODDEF) */520521#ifndef _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF522#define _MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF523#endif /* !defined(_MULTIPROCESSING_SEMLOCK__IS_MINE_METHODDEF) */524525#ifndef _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF526#define _MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF527#endif /* !defined(_MULTIPROCESSING_SEMLOCK__GET_VALUE_METHODDEF) */528529#ifndef _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF530#define _MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF531#endif /* !defined(_MULTIPROCESSING_SEMLOCK__IS_ZERO_METHODDEF) */532533#ifndef _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF534#define _MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF535#endif /* !defined(_MULTIPROCESSING_SEMLOCK__AFTER_FORK_METHODDEF) */536537#ifndef _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF538#define _MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF539#endif /* !defined(_MULTIPROCESSING_SEMLOCK___ENTER___METHODDEF) */540541#ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF542#define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF543#endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */544/*[clinic end generated code: output=dae57a702cc01512 input=a9049054013a1b77]*/545546547