Cython: _semaphore.py

Generated by Cython 3.0.0a11

Yellow lines hint at Python interaction.
Click on a line that starts with a "`+`" to see the C code that Cython generated for it.

Raw output: _semaphore.c

    +001: # cython: auto_pickle=False,embedsignature=True,always_allow_keywords=False

    __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     002: ###

     003: # This file is ``gevent._semaphore`` so that it can be compiled by Cython

     004: # individually. However, this is not the place to import from. Everyone,

     005: # gevent internal code included, must import from ``gevent.lock``.

     006: # The only exception are .pxd files which need access to the

     007: # C code; the PURE_PYTHON things that have to happen and which are

     008: # handled in ``gevent.lock``, do not apply to them.

     009: ###

     010: from __future__ import print_function, absolute_import, division

     011:

    +012: __all__ = [

    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_n_s_Semaphore);__Pyx_GIVEREF(__pyx_n_s_Semaphore);PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Semaphore);__Pyx_INCREF(__pyx_n_s_BoundedSemaphore);__Pyx_GIVEREF(__pyx_n_s_BoundedSemaphore);PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_BoundedSemaphore);if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) __PYX_ERR(0, 12, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

     013:     'Semaphore',

     014:     'BoundedSemaphore',

     015: ]

     016:

    +017: from time import sleep as _native_sleep

    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_n_s_sleep);__Pyx_GIVEREF(__pyx_n_s_sleep);PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_sleep);__pyx_t_3 = __Pyx_Import(__pyx_n_s_time, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 17, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_sleep); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_t_2);__Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore__native_sleep);__Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore__native_sleep, __pyx_t_2);__Pyx_GIVEREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     018:

    +019: from gevent._compat import monotonic

    __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF(__pyx_n_s_monotonic);__Pyx_GIVEREF(__pyx_n_s_monotonic);PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_monotonic);__pyx_t_2 = __Pyx_Import(__pyx_n_s_gevent__compat, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_monotonic); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF(__pyx_t_3);__Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);__Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic, __pyx_t_3);__Pyx_GIVEREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +020: from gevent.exceptions import InvalidThreadUseError

    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_n_s_InvalidThreadUseError);__Pyx_GIVEREF(__pyx_n_s_InvalidThreadUseError);PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_InvalidThreadUseError);__pyx_t_3 = __Pyx_Import(__pyx_n_s_gevent_exceptions, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 20, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_InvalidThreadUseError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_t_2);__Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore_InvalidThreadUseError);__Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore_InvalidThreadUseError, __pyx_t_2);__Pyx_GIVEREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    +021: from gevent.exceptions import LoopExit

    __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 21, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF(__pyx_n_s_LoopExit);__Pyx_GIVEREF(__pyx_n_s_LoopExit);PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_LoopExit);__pyx_t_2 = __Pyx_Import(__pyx_n_s_gevent_exceptions, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_LoopExit); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 21, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF(__pyx_t_3);__Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore_LoopExit);__Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore_LoopExit, __pyx_t_3);__Pyx_GIVEREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +022: from gevent.timeout import Timeout

    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_n_s_Timeout);__Pyx_GIVEREF(__pyx_n_s_Timeout);PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Timeout);__pyx_t_3 = __Pyx_Import(__pyx_n_s_gevent_timeout, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Timeout); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_t_2);__Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore_Timeout);__Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore_Timeout, __pyx_t_2);__Pyx_GIVEREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     023:

    +024: def _get_linkable():

    /* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_1_get_linkable(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore__get_linkable, "_get_linkable()");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_1_get_linkable = {"_get_linkable", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_1_get_linkable, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore__get_linkable};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_1_get_linkable(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_get_linkable (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore__get_linkable(__pyx_self);/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore__get_linkable(CYTHON_UNUSED PyObject *__pyx_self) {PyObject *__pyx_v_x = NULL;PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_get_linkable", 0);/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_AddTraceback("gevent._gevent_c_semaphore._get_linkable", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XDECREF(__pyx_v_x);__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_tuple__6 = PyTuple_Pack(1, __pyx_n_s_x); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 24, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__6);__Pyx_GIVEREF(__pyx_tuple__6);__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_1_get_linkable, 0, __pyx_n_s_get_linkable, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__7)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_linkable, __pyx_t_3) < 0) __PYX_ERR(0, 24, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_get_linkable, 24, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 24, __pyx_L1_error)

    +025:     x = __import__('gevent._abstract_linkable')

    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin___import__, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_v_x = __pyx_t_1;__pyx_t_1 = 0;__pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_gevent__abstract_linkable); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 25, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple_);__Pyx_GIVEREF(__pyx_tuple_);

    +026:     return x._abstract_linkable.AbstractLinkable

    __Pyx_XDECREF(__pyx_r);__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_n_s_abstract_linkable); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_AbstractLinkable); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__pyx_r = __pyx_t_2;__pyx_t_2 = 0;goto __pyx_L0;

    +027: locals()['AbstractLinkable'] = _get_linkable()

    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_get_linkable); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 27, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_3 = __Pyx_Globals(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 27, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (unlikely((PyDict_SetItem(__pyx_t_3, __pyx_n_s_AbstractLinkable, __pyx_t_2) < 0))) __PYX_ERR(0, 27, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +028: del _get_linkable

    if (__Pyx_PyObject_DelAttrStr(__pyx_m, __pyx_n_s_get_linkable) < 0) __PYX_ERR(0, 28, __pyx_L1_error)

     029:

    +030: from gevent._hub_local import get_hub_if_exists

    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_n_s_get_hub_if_exists);__Pyx_GIVEREF(__pyx_n_s_get_hub_if_exists);PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_get_hub_if_exists);__pyx_t_3 = __Pyx_Import(__pyx_n_s_gevent__hub_local, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_get_hub_if_exists); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 30, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_hub_if_exists, __pyx_t_2) < 0) __PYX_ERR(0, 30, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    +031: from gevent._hub_local import get_hub

    __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF(__pyx_n_s_get_hub);__Pyx_GIVEREF(__pyx_n_s_get_hub);PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_get_hub);__pyx_t_2 = __Pyx_Import(__pyx_n_s_gevent__hub_local, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_get_hub); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_hub_noargs, __pyx_t_3) < 0) __PYX_ERR(0, 31, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +032: from gevent.hub import spawn_raw

    __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_n_s_spawn_raw);__Pyx_GIVEREF(__pyx_n_s_spawn_raw);PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_spawn_raw);__pyx_t_3 = __Pyx_Import(__pyx_n_s_gevent_hub, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_spawn_raw); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_t_2);__Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore_spawn_raw);__Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore_spawn_raw, __pyx_t_2);__Pyx_GIVEREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     033:

     034: class _LockReleaseLink(object):

     035:     __slots__ = (

    +036:         'lock',

    if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore__LockReleaseLink->tp_dict, __pyx_n_s_slots, __pyx_tuple__8) < 0) __PYX_ERR(0, 35, __pyx_L1_error)PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore__LockReleaseLink);__pyx_tuple__8 = PyTuple_Pack(1, __pyx_n_s_lock); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 36, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__8);__Pyx_GIVEREF(__pyx_tuple__8);

     037:     )

     038:

    +039:     def __init__(self, lock):

    /* Python wrapper */static int __pyx_pw_6gevent_19_gevent_c_semaphore_16_LockReleaseLink_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/static int __pyx_pw_6gevent_19_gevent_c_semaphore_16_LockReleaseLink_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {PyObject *__pyx_v_lock = 0;CYTHON_UNUSED const Py_ssize_t __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);{#if CYTHON_USE_MODULE_STATEPyObject **__pyx_pyargnames[] = {&__pyx_n_s_lock,0};#elsestatic PyObject **__pyx_pyargnames[] = {&__pyx_n_s_lock,0};#endifPyObject* values[1] = {0};if (__pyx_kwds) {Py_ssize_t kw_args;switch (__pyx_nargs) {case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);switch (__pyx_nargs) {case  0:if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_lock)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 39, __pyx_L3_error)else goto __pyx_L5_argtuple_error;}if (unlikely(kw_args > 0)) {const Py_ssize_t kwd_pos_args = __pyx_nargs;if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 39, __pyx_L3_error)}} else if (unlikely(__pyx_nargs != 1)) {goto __pyx_L5_argtuple_error;} else {values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);}__pyx_v_lock = values[0];}goto __pyx_L4_argument_unpacking_done;__pyx_L5_argtuple_error:;__Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 39, __pyx_L3_error)__pyx_L3_error:;__Pyx_AddTraceback("gevent._gevent_c_semaphore._LockReleaseLink.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);__Pyx_RefNannyFinishContext();return -1;__pyx_L4_argument_unpacking_done:;__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_16_LockReleaseLink___init__(((struct __pyx_obj_6gevent_19_gevent_c_semaphore__LockReleaseLink *)__pyx_v_self), __pyx_v_lock);int __pyx_lineno = 0;const char *__pyx_filename = NULL;int __pyx_clineno = 0;/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static int __pyx_pf_6gevent_19_gevent_c_semaphore_16_LockReleaseLink___init__(struct __pyx_obj_6gevent_19_gevent_c_semaphore__LockReleaseLink *__pyx_v_self, PyObject *__pyx_v_lock) {int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__init__", 0);/* function exit code */__pyx_r = 0;__Pyx_RefNannyFinishContext();return __pyx_r;}

    +040:         self.lock = lock

    __Pyx_INCREF(__pyx_v_lock);__Pyx_GIVEREF(__pyx_v_lock);__Pyx_GOTREF(__pyx_v_self->lock);__Pyx_DECREF(__pyx_v_self->lock);__pyx_v_self->lock = __pyx_v_lock;

     041:

    +042:     def __call__(self, _):

    /* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_16_LockReleaseLink_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_16_LockReleaseLink_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {CYTHON_UNUSED PyObject *__pyx_v__ = 0;CYTHON_UNUSED const Py_ssize_t __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__call__ (wrapper)", 0);{#if CYTHON_USE_MODULE_STATEPyObject **__pyx_pyargnames[] = {&__pyx_n_s__2,0};#elsestatic PyObject **__pyx_pyargnames[] = {&__pyx_n_s__2,0};#endifPyObject* values[1] = {0};if (__pyx_kwds) {Py_ssize_t kw_args;switch (__pyx_nargs) {case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);switch (__pyx_nargs) {case  0:if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s__2)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 42, __pyx_L3_error)else goto __pyx_L5_argtuple_error;}if (unlikely(kw_args > 0)) {const Py_ssize_t kwd_pos_args = __pyx_nargs;if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__call__") < 0)) __PYX_ERR(0, 42, __pyx_L3_error)}} else if (unlikely(__pyx_nargs != 1)) {goto __pyx_L5_argtuple_error;} else {values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);}__pyx_v__ = values[0];}goto __pyx_L4_argument_unpacking_done;__pyx_L5_argtuple_error:;__Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 42, __pyx_L3_error)__pyx_L3_error:;__Pyx_AddTraceback("gevent._gevent_c_semaphore._LockReleaseLink.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);__Pyx_RefNannyFinishContext();return NULL;__pyx_L4_argument_unpacking_done:;__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_16_LockReleaseLink_2__call__(((struct __pyx_obj_6gevent_19_gevent_c_semaphore__LockReleaseLink *)__pyx_v_self), __pyx_v__);int __pyx_lineno = 0;const char *__pyx_filename = NULL;int __pyx_clineno = 0;/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_16_LockReleaseLink_2__call__(struct __pyx_obj_6gevent_19_gevent_c_semaphore__LockReleaseLink *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v__) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__call__", 0);/* function exit code */__pyx_r = Py_None; __Pyx_INCREF(Py_None);goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_AddTraceback("gevent._gevent_c_semaphore._LockReleaseLink.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}

    +043:         self.lock.release()

    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->lock, __pyx_n_s_release); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_3 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_3, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     044:

    +045: _UNSET = object()

    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_builtin_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 45, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore__UNSET);__Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore__UNSET, __pyx_t_3);__Pyx_GIVEREF(__pyx_t_3);__pyx_t_3 = 0;

    +046: _MULTI = object()

    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_builtin_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 46, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore__MULTI);__Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore__MULTI, __pyx_t_3);__Pyx_GIVEREF(__pyx_t_3);__pyx_t_3 = 0;

     047:

    +048: class Semaphore(AbstractLinkable): # pylint:disable=undefined-variable

    struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore {struct __pyx_vtabstruct_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable __pyx_base;int (*locked)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, int __pyx_skip_dispatch);int (*release)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, int __pyx_skip_dispatch);PyObject *(*_start_notify)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, int __pyx_skip_dispatch);int (*wait)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_19_gevent_c_semaphore_9Semaphore_wait *__pyx_optional_args);int (*acquire)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_19_gevent_c_semaphore_9Semaphore_acquire *__pyx_optional_args);PyObject *(*__pyx___enter__)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, int __pyx_skip_dispatch);PyObject *(*__pyx___exit__)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch);PyObject *(*_Semaphore__acquire_from_other_thread)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, PyObject *, int, PyObject *);PyObject *(*_Semaphore__acquire_from_other_thread_cb)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, PyObject *, int, PyObject *, PyObject *, int __pyx_skip_dispatch);PyObject *(*_Semaphore__add_link)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, PyObject *);PyObject *(*_Semaphore__acquire_using_two_hubs)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *, PyObject *, PyObject *);PyObject *(*_Semaphore__acquire_using_other_hub)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *, PyObject *);int (*_Semaphore__acquire_without_hubs)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, PyObject *);int (*_Semaphore__spin_on_native_lock)(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *, PyObject *, PyObject *);};static struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_vtabptr_6gevent_19_gevent_c_semaphore_Semaphore;

     049:     """

     050:     Semaphore(value=1) -> Semaphore

     051:

     052:     .. seealso:: :class:`BoundedSemaphore` for a safer version that prevents

     053:        some classes of bugs. If unsure, most users should opt for `BoundedSemaphore`.

     054:

     055:     A semaphore manages a counter representing the number of `release`

     056:     calls minus the number of `acquire` calls, plus an initial value.

     057:     The `acquire` method blocks if necessary until it can return

     058:     without making the counter negative. A semaphore does not track ownership

     059:     by greenlets; any greenlet can call `release`, whether or not it has previously

     060:     called `acquire`.

     061:

     062:     If not given, ``value`` defaults to 1.

     063:

     064:     The semaphore is a context manager and can be used in ``with`` statements.

     065:

     066:     This Semaphore's ``__exit__`` method does not call the trace function

     067:     on CPython, but does under PyPy.

     068:

     069:     .. versionchanged:: 1.4.0

     070:         Document that the order in which waiters are awakened is not specified. It was not

     071:         specified previously, but due to CPython implementation quirks usually went in FIFO order.

     072:     .. versionchanged:: 1.5a3

     073:        Waiting greenlets are now awakened in the order in which they waited.

     074:     .. versionchanged:: 1.5a3

     075:        The low-level ``rawlink`` method (most users won't use this) now automatically

     076:        unlinks waiters before calling them.

     077:     .. versionchanged:: 20.12.0

     078:        Improved support for multi-threaded usage. When multi-threaded usage is detected,

     079:        instances will no longer create the thread's hub if it's not present.

     080:     """

     081:

     082:     __slots__ = (

    +083:         'counter',

    if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_slots, __pyx_tuple__9) < 0) __PYX_ERR(0, 82, __pyx_L1_error)PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_counter, __pyx_n_s_multithreaded); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 83, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__9);__Pyx_GIVEREF(__pyx_tuple__9);

     084:         # long integer, signed (Py2) or unsigned (Py3); see comments

     085:         # in the .pxd file for why we store as Python object. Set to ``_UNSET``

     086:         # initially. Set to the ident of the first thread that

     087:         # acquires us. If we later see a different thread ident, set

     088:         # to ``_MULTI``.

     089:         '_multithreaded',

     090:     )

     091:

    +092:     def __init__(self, value=1, hub=None):

    /* Python wrapper */static int __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/static int __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {PyObject *__pyx_v_value = 0;PyObject *__pyx_v_hub = 0;CYTHON_UNUSED const Py_ssize_t __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);{#if CYTHON_USE_MODULE_STATEPyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_hub,0};#elsestatic PyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_hub,0};#endifPyObject* values[2] = {0,0};values[0] = ((PyObject *)__pyx_int_1);values[1] = ((PyObject *)Py_None);if (__pyx_kwds) {Py_ssize_t kw_args;switch (__pyx_nargs) {case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);CYTHON_FALLTHROUGH;case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);switch (__pyx_nargs) {case  0:if (kw_args > 0) {PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_value);if (value) { values[0] = value; kw_args--; }else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 92, __pyx_L3_error)}CYTHON_FALLTHROUGH;case  1:if (kw_args > 0) {PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_hub);if (value) { values[1] = value; kw_args--; }else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 92, __pyx_L3_error)}}if (unlikely(kw_args > 0)) {const Py_ssize_t kwd_pos_args = __pyx_nargs;if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 92, __pyx_L3_error)}} else {switch (__pyx_nargs) {case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);CYTHON_FALLTHROUGH;case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}}__pyx_v_value = values[0];__pyx_v_hub = values[1];}goto __pyx_L4_argument_unpacking_done;__pyx_L5_argtuple_error:;__Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 2, __pyx_nargs); __PYX_ERR(0, 92, __pyx_L3_error)__pyx_L3_error:;__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);__Pyx_RefNannyFinishContext();return -1;__pyx_L4_argument_unpacking_done:;__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore___init__(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self), __pyx_v_value, __pyx_v_hub);/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static int __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore___init__(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_value, PyObject *__pyx_v_hub) {int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__init__", 0);/* function exit code */__pyx_r = 0;goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_XDECREF(__pyx_t_5);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = -1;__pyx_L0:;__Pyx_RefNannyFinishContext();return __pyx_r;}

    +093:         self.counter = value

    __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 93, __pyx_L1_error)__pyx_v_self->counter = __pyx_t_1;

    +094:         if self.counter < 0: # Do the check after Cython native int conversion

    __pyx_t_2 = (__pyx_v_self->counter < 0);if (unlikely(__pyx_t_2)) {}

    +095:             raise ValueError("semaphore initial value must be >= 0")

    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 95, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_Raise(__pyx_t_3, 0, 0, 0);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__PYX_ERR(0, 95, __pyx_L1_error)__pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_semaphore_initial_value_must_be); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 95, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__3);__Pyx_GIVEREF(__pyx_tuple__3);

    +096:         super(Semaphore, self).__init__(hub)

    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 96, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_INCREF((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__Pyx_GIVEREF((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore));__Pyx_INCREF((PyObject *)__pyx_v_self);__Pyx_GIVEREF((PyObject *)__pyx_v_self);PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_self));__pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 96, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_5);__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_init); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 96, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;__pyx_t_5 = NULL;__pyx_t_1 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);if (likely(__pyx_t_5)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);__Pyx_INCREF(__pyx_t_5);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_4, function);__pyx_t_1 = 1;}}{PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_hub};__pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_1, 1+__pyx_t_1);__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;}__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    +097:         self._notify_all = False

    __pyx_v_self->__pyx_base._notify_all = 0;

    +098:         self._multithreaded = _UNSET

    __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore__UNSET);__Pyx_GIVEREF(__pyx_v_6gevent_19_gevent_c_semaphore__UNSET);__Pyx_GOTREF(__pyx_v_self->_multithreaded);__Pyx_DECREF(__pyx_v_self->_multithreaded);__pyx_v_self->_multithreaded = __pyx_v_6gevent_19_gevent_c_semaphore__UNSET;

     099:

    +100:     def __str__(self):

    /* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_3__str__(PyObject *__pyx_v_self); /*proto*/static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_3__str__(PyObject *__pyx_v_self) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__str__ (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_2__str__(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self));/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_2__str__(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__str__", 0);/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_XDECREF(__pyx_t_5);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}

    +101:         return '<%s at 0x%x counter=%s _links[%s]>' % (

    __Pyx_XDECREF(__pyx_r);__pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_at_0x_x_counter_s__links_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;__pyx_r = __pyx_t_4;__pyx_t_4 = 0;goto __pyx_L0;

    +102:             self.__class__.__name__,

    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 102, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 102, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_5);__Pyx_GIVEREF(__pyx_t_2);PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);__Pyx_GIVEREF(__pyx_t_1);PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);__Pyx_GIVEREF(__pyx_t_3);PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);__Pyx_GIVEREF(__pyx_t_4);PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4);__pyx_t_2 = 0;__pyx_t_1 = 0;__pyx_t_3 = 0;__pyx_t_4 = 0;

    +103:             id(self),

    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);

    +104:             self.counter,

    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->counter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 104, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);

    +105:             self.linkcount()

    __pyx_t_4 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.linkcount(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);

     106:         )

     107:

    +108:     def locked(self):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/static int __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_locked(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("locked", 0);/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_locked); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked)) {__Pyx_INCREF(__pyx_t_1);__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_r = __pyx_t_6;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_WriteUnraisable("gevent._gevent_c_semaphore.Semaphore.locked", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);__pyx_r = 0;__pyx_L0:;__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_4locked, "Semaphore.locked(self) -> bool\n\n        Return a boolean indicating whether the semaphore can be\n        acquired (`False` if the semaphore *can* be acquired). Most\n        useful with binary semaphores (those with an initial value of 1).\n\n        :rtype: bool\n        ");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_5locked = {"locked", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_4locked};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("locked (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_4locked(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self));/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_4locked(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("locked", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_locked(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.locked", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_tuple__10 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 108, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__10);__Pyx_GIVEREF(__pyx_tuple__10);__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_5locked, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_locked, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 108, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_locked, __pyx_t_3) < 0) __PYX_ERR(0, 108, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_locked, 108, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 108, __pyx_L1_error)

     109:         """

     110:         Return a boolean indicating whether the semaphore can be

     111:         acquired (`False` if the semaphore *can* be acquired). Most

     112:         useful with binary semaphores (those with an initial value of 1).

     113:

     114:         :rtype: bool

     115:         """

    +116:         return self.counter <= 0

    __pyx_r = (__pyx_v_self->counter <= 0);goto __pyx_L0;

     117:

    +118:     def release(self):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/static int __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_release(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("release", 0);/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_release); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release)) {__Pyx_INCREF(__pyx_t_1);__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 118, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_r = __pyx_t_5;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.release", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = -1000;__pyx_L0:;__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_6release, "Semaphore.release(self) -> int\n\n        Release the semaphore, notifying any waiters if needed. There\n        is no return value.\n\n        .. note::\n\n            This can be used to over-release the semaphore.\n            (Release more times than it has been acquired or was initially\n            created with.)\n\n            This is usually a sign of a bug, but under some circumstances it can be\n            used deliberately, for example, to model the arrival of additional\n            resources.\n\n        :rtype: None\n        ");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_7release = {"release", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_6release};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("release (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_6release(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self));/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_6release(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("release", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_1 = __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_release(__pyx_v_self, 1); if (unlikely(__pyx_t_1 == ((int)-1000))) __PYX_ERR(0, 118, __pyx_L1_error)__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_r = __pyx_t_2;__pyx_t_2 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_2);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.release", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_7release, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_release, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__12)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 118, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_release, __pyx_t_3) < 0) __PYX_ERR(0, 118, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_release, 118, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 118, __pyx_L1_error)

     119:         """

     120:         Release the semaphore, notifying any waiters if needed. There

     121:         is no return value.

     122:

     123:         .. note::

     124:

     125:             This can be used to over-release the semaphore.

     126:             (Release more times than it has been acquired or was initially

     127:             created with.)

     128:

     129:             This is usually a sign of a bug, but under some circumstances it can be

     130:             used deliberately, for example, to model the arrival of additional

     131:             resources.

     132:

     133:         :rtype: None

     134:         """

    +135:         self.counter += 1

    __pyx_v_self->counter = (__pyx_v_self->counter + 1);

    +136:         self._check_and_notify()

    __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._check_and_notify(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +137:         return self.counter

    __pyx_r = __pyx_v_self->counter;goto __pyx_L0;

     138:

    +139:     def ready(self):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/static int __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_ready(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("ready", 0);/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_ready); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready)) {__Pyx_INCREF(__pyx_t_1);__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 139, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 139, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_r = __pyx_t_6;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_WriteUnraisable("gevent._gevent_c_semaphore.Semaphore.ready", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);__pyx_r = 0;__pyx_L0:;__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_8ready, "Semaphore.ready(self) -> bool\n\n        Return a boolean indicating whether the semaphore can be\n        acquired (`True` if the semaphore can be acquired).\n\n        :rtype: bool\n        ");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_9ready = {"ready", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_8ready};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("ready (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_8ready(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self));/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_8ready(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("ready", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_ready(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.ready", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_9ready, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_ready, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 139, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_ready, __pyx_t_3) < 0) __PYX_ERR(0, 139, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_ready, 139, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 139, __pyx_L1_error)

     140:         """

     141:         Return a boolean indicating whether the semaphore can be

     142:         acquired (`True` if the semaphore can be acquired).

     143:

     144:         :rtype: bool

     145:         """

    +146:         return self.counter > 0

    __pyx_r = (__pyx_v_self->counter > 0);goto __pyx_L0;

     147:

    +148:     def _start_notify(self):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__start_notify(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_start_notify", 0);/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start_notify); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify)) {__Pyx_XDECREF(__pyx_r);__Pyx_INCREF(__pyx_t_1);__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_r = __pyx_t_2;__pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_r = Py_None; __Pyx_INCREF(Py_None);goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._start_notify", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_10_start_notify, "Semaphore._start_notify(self)");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify = {"_start_notify", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_10_start_notify};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_start_notify (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_10_start_notify(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self));/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_10_start_notify(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_start_notify", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_1 = __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__start_notify(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._start_notify", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore__start_notify, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 148, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_start_notify, __pyx_t_3) < 0) __PYX_ERR(0, 148, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_start_notify, 148, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 148, __pyx_L1_error)

    +149:         self._check_and_notify()

    __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._check_and_notify(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     150:

    +151:     def _wait_return_value(self, waited, wait_success):

    static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__wait_return_value(CYTHON_UNUSED struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_v_waited, int __pyx_v_wait_success) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_wait_return_value", 0);/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._wait_return_value", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}

    +152:         if waited:

    if (__pyx_v_waited) {}

    +153:             return wait_success

    __Pyx_XDECREF(__pyx_r);__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_wait_success); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;

     154:         # We didn't even wait, we must be good to go.

     155:         # XXX: This is probably dead code, we're careful not to go into the wait

     156:         # state if we don't expect to need to

    +157:         return True

    __Pyx_XDECREF(__pyx_r);__Pyx_INCREF(Py_True);__pyx_r = Py_True;goto __pyx_L0;

     158:

    +159:     def wait(self, timeout=None):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/static int __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_wait(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_19_gevent_c_semaphore_9Semaphore_wait *__pyx_optional_args) {PyObject *__pyx_v_timeout = ((PyObject *)Py_None);int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("wait", 0);if (__pyx_optional_args) {if (__pyx_optional_args->__pyx_n > 0) {__pyx_v_timeout = __pyx_optional_args->timeout;}}/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_wait); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait)) {__Pyx_INCREF(__pyx_t_1);__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_timeout};__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 159, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_r = __pyx_t_5;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.wait", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = -1000;__pyx_L0:;__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_12wait, "Semaphore.wait(self, timeout=None) -> int\n\n        Wait until it is possible to acquire this semaphore, or until the optional\n        *timeout* elapses.\n\n        .. note:: If this semaphore was initialized with a *value* of 0,\n           this method will block forever if no timeout is given.\n\n        :keyword float timeout: If given, specifies the maximum amount of seconds\n           this method will block.\n        :return: A number indicating how many times the semaphore can be acquired\n            before blocking. *This could be 0,* if other waiters acquired\n            the semaphore.\n        :rtype: int\n        ");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_13wait = {"wait", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_12wait};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {PyObject *__pyx_v_timeout = 0;#if !CYTHON_METH_FASTCALLCYTHON_UNUSED const Py_ssize_t __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);#endifCYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("wait (wrapper)", 0);{#if CYTHON_USE_MODULE_STATEPyObject **__pyx_pyargnames[] = {&__pyx_n_s_timeout,0};#elsestatic PyObject **__pyx_pyargnames[] = {&__pyx_n_s_timeout,0};#endifPyObject* values[1] = {0};values[0] = ((PyObject *)Py_None);if (__pyx_kwds) {Py_ssize_t kw_args;switch (__pyx_nargs) {case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);switch (__pyx_nargs) {case  0:if (kw_args > 0) {PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_timeout);if (value) { values[0] = value; kw_args--; }else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 159, __pyx_L3_error)}}if (unlikely(kw_args > 0)) {const Py_ssize_t kwd_pos_args = __pyx_nargs;if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "wait") < 0)) __PYX_ERR(0, 159, __pyx_L3_error)}} else {switch (__pyx_nargs) {case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}}__pyx_v_timeout = values[0];}goto __pyx_L4_argument_unpacking_done;__pyx_L5_argtuple_error:;__Pyx_RaiseArgtupleInvalid("wait", 0, 0, 1, __pyx_nargs); __PYX_ERR(0, 159, __pyx_L3_error)__pyx_L3_error:;__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.wait", __pyx_clineno, __pyx_lineno, __pyx_filename);__Pyx_RefNannyFinishContext();return NULL;__pyx_L4_argument_unpacking_done:;__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_12wait(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self), __pyx_v_timeout);/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_12wait(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_timeout) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("wait", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_2.__pyx_n = 1;__pyx_t_2.timeout = __pyx_v_timeout;__pyx_t_1 = __pyx_vtabptr_6gevent_19_gevent_c_semaphore_Semaphore->wait(__pyx_v_self, 1, &__pyx_t_2); if (unlikely(__pyx_t_1 == ((int)-1000))) __PYX_ERR(0, 159, __pyx_L1_error)__pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 159, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_r = __pyx_t_3;__pyx_t_3 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_3);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.wait", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_tuple__15 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_timeout); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 159, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__15);__Pyx_GIVEREF(__pyx_tuple__15);__pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_wait, 159, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 159, __pyx_L1_error)__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_13wait, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_wait, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 159, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_tuple__17);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_wait, __pyx_t_3) < 0) __PYX_ERR(0, 159, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_tuple__17 = PyTuple_Pack(1, Py_None); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 159, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__17);__Pyx_GIVEREF(__pyx_tuple__17);

     160:         """

     161:         Wait until it is possible to acquire this semaphore, or until the optional

     162:         *timeout* elapses.

     163:

     164:         .. note:: If this semaphore was initialized with a *value* of 0,

     165:            this method will block forever if no timeout is given.

     166:

     167:         :keyword float timeout: If given, specifies the maximum amount of seconds

     168:            this method will block.

     169:         :return: A number indicating how many times the semaphore can be acquired

     170:             before blocking. *This could be 0,* if other waiters acquired

     171:             the semaphore.

     172:         :rtype: int

     173:         """

    +174:         if self.counter > 0:

    __pyx_t_6 = (__pyx_v_self->counter > 0);if (__pyx_t_6) {}

    +175:             return self.counter

    __pyx_r = __pyx_v_self->counter;goto __pyx_L0;

     176:

    +177:         self._wait(timeout) # return value irrelevant, whether we got it or got a timeout

    __pyx_t_7.__pyx_n = 1;__pyx_t_7.timeout = __pyx_v_timeout;__pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._wait(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), &__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +178:         return self.counter

    __pyx_r = __pyx_v_self->counter;goto __pyx_L0;

     179:

    +180:     def acquire(self, blocking=True, timeout=None):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/static int __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_acquire(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_19_gevent_c_semaphore_9Semaphore_acquire *__pyx_optional_args) {int __pyx_v_blocking = ((int)1);PyObject *__pyx_v_timeout = ((PyObject *)Py_None);int __pyx_v_success;PyObject *__pyx_v_e = 0;PyObject *__pyx_v_ex = 0;PyObject *__pyx_v_args = 0;PyObject *__pyx_v_invalid_thread_use = NULL;int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("acquire", 0);if (__pyx_optional_args) {if (__pyx_optional_args->__pyx_n > 0) {__pyx_v_blocking = __pyx_optional_args->blocking;if (__pyx_optional_args->__pyx_n > 1) {__pyx_v_timeout = __pyx_optional_args->timeout;}}}/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_acquire); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire)) {__pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_blocking); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF(__pyx_t_1);__pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL;__pyx_t_6 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);if (likely(__pyx_t_5)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);__Pyx_INCREF(__pyx_t_5);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_4, function);__pyx_t_6 = 1;}}{PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_t_3, __pyx_v_timeout};__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 2+__pyx_t_6);__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;}__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_r = __pyx_t_7;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_XDECREF(__pyx_t_5);__Pyx_XDECREF(__pyx_t_23);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.acquire", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = -1000;__pyx_L0:;__Pyx_XDECREF(__pyx_v_e);__Pyx_XDECREF(__pyx_v_ex);__Pyx_XDECREF(__pyx_v_args);__Pyx_XDECREF(__pyx_v_invalid_thread_use);__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_14acquire, "Semaphore.acquire(self, bool blocking=True, timeout=None) -> bool\n\n        acquire(blocking=True, timeout=None) -> bool\n\n        Acquire the semaphore.\n\n        .. note:: If this semaphore was initialized with a *value* of 0,\n           this method will block forever (unless a timeout is given or blocking is\n           set to false).\n\n        :keyword bool blocking: If True (the default), this function will block\n           until the semaphore is acquired.\n        :keyword float timeout: If given, and *blocking* is true,\n           specifies the maximum amount of seconds\n           this method will block.\n        :return: A `bool` indicating whether the semaphore was acquired.\n           If ``blocking`` is True and ``timeout`` is None (the default), then\n           (so long as this semaphore was initialized with a size greater than 0)\n           this will always return True. If a timeout was given, and it expired before\n           the semaphore was acquired, False will be returned. (Note that this can still\n           raise a ``Timeout`` exception, if some other caller had already started a timer.)\n        ");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire = {"acquire", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_14acquire};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {int __pyx_v_blocking;PyObject *__pyx_v_timeout = 0;#if !CYTHON_METH_FASTCALLCYTHON_UNUSED const Py_ssize_t __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);#endifCYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("acquire (wrapper)", 0);{#if CYTHON_USE_MODULE_STATEPyObject **__pyx_pyargnames[] = {&__pyx_n_s_blocking,&__pyx_n_s_timeout,0};#elsestatic PyObject **__pyx_pyargnames[] = {&__pyx_n_s_blocking,&__pyx_n_s_timeout,0};#endifPyObject* values[2] = {0,0};values[1] = ((PyObject *)Py_None);if (__pyx_kwds) {Py_ssize_t kw_args;switch (__pyx_nargs) {case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);CYTHON_FALLTHROUGH;case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);switch (__pyx_nargs) {case  0:if (kw_args > 0) {PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_blocking);if (value) { values[0] = value; kw_args--; }else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 180, __pyx_L3_error)}CYTHON_FALLTHROUGH;case  1:if (kw_args > 0) {PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_timeout);if (value) { values[1] = value; kw_args--; }else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 180, __pyx_L3_error)}}if (unlikely(kw_args > 0)) {const Py_ssize_t kwd_pos_args = __pyx_nargs;if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "acquire") < 0)) __PYX_ERR(0, 180, __pyx_L3_error)}} else {switch (__pyx_nargs) {case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);CYTHON_FALLTHROUGH;case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}}if (values[0]) {__pyx_v_blocking = __Pyx_PyObject_IsTrue(values[0]); if (unlikely((__pyx_v_blocking == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 180, __pyx_L3_error)} else {__pyx_v_blocking = ((int)1);}__pyx_v_timeout = values[1];}goto __pyx_L4_argument_unpacking_done;__pyx_L5_argtuple_error:;__Pyx_RaiseArgtupleInvalid("acquire", 0, 0, 2, __pyx_nargs); __PYX_ERR(0, 180, __pyx_L3_error)__pyx_L3_error:;__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.acquire", __pyx_clineno, __pyx_lineno, __pyx_filename);__Pyx_RefNannyFinishContext();return NULL;__pyx_L4_argument_unpacking_done:;__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_14acquire(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self), __pyx_v_blocking, __pyx_v_timeout);/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_14acquire(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_v_blocking, PyObject *__pyx_v_timeout) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("acquire", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_2.__pyx_n = 2;__pyx_t_2.blocking = __pyx_v_blocking;__pyx_t_2.timeout = __pyx_v_timeout;__pyx_t_1 = __pyx_vtabptr_6gevent_19_gevent_c_semaphore_Semaphore->acquire(__pyx_v_self, 1, &__pyx_t_2); if (unlikely(__pyx_t_1 == ((int)-1000))) __PYX_ERR(0, 180, __pyx_L1_error)__pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_r = __pyx_t_3;__pyx_t_3 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_3);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.acquire", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_tuple__18 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_blocking, __pyx_n_s_timeout); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__18);__Pyx_GIVEREF(__pyx_tuple__18);__pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_acquire, 180, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 180, __pyx_L1_error)__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_acquire, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__19)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_tuple__20);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_acquire, __pyx_t_3) < 0) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_tuple__20 = PyTuple_Pack(2, Py_True, Py_None); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 180, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__20);__Pyx_GIVEREF(__pyx_tuple__20);

     181:         """

     182:         acquire(blocking=True, timeout=None) -> bool

     183:

     184:         Acquire the semaphore.

     185:

     186:         .. note:: If this semaphore was initialized with a *value* of 0,

     187:            this method will block forever (unless a timeout is given or blocking is

     188:            set to false).

     189:

     190:         :keyword bool blocking: If True (the default), this function will block

     191:            until the semaphore is acquired.

     192:         :keyword float timeout: If given, and *blocking* is true,

     193:            specifies the maximum amount of seconds

     194:            this method will block.

     195:         :return: A `bool` indicating whether the semaphore was acquired.

     196:            If ``blocking`` is True and ``timeout`` is None (the default), then

     197:            (so long as this semaphore was initialized with a size greater than 0)

     198:            this will always return True. If a timeout was given, and it expired before

     199:            the semaphore was acquired, False will be returned. (Note that this can still

     200:            raise a ``Timeout`` exception, if some other caller had already started a timer.)

     201:         """

     202:         # pylint:disable=too-many-return-statements,too-many-branches

     203:         # Sadly, the body of this method is rather complicated.

    +204:         if self._multithreaded is _UNSET:

    __pyx_t_7 = (__pyx_v_self->_multithreaded == __pyx_v_6gevent_19_gevent_c_semaphore__UNSET);if (__pyx_t_7) {goto __pyx_L3;}

    +205:             self._multithreaded = self._get_thread_ident()

    __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._get_thread_ident(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_GIVEREF(__pyx_t_1);__Pyx_GOTREF(__pyx_v_self->_multithreaded);__Pyx_DECREF(__pyx_v_self->_multithreaded);__pyx_v_self->_multithreaded = __pyx_t_1;__pyx_t_1 = 0;

    +206:         elif self._multithreaded != self._get_thread_ident():

    __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._get_thread_ident(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 206, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_t_2 = PyObject_RichCompare(__pyx_v_self->_multithreaded, __pyx_t_1, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 206, __pyx_L1_error)__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 206, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;if (__pyx_t_7) {}__pyx_L3:;

    +207:             self._multithreaded = _MULTI

    __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore__MULTI);__Pyx_GIVEREF(__pyx_v_6gevent_19_gevent_c_semaphore__MULTI);__Pyx_GOTREF(__pyx_v_self->_multithreaded);__Pyx_DECREF(__pyx_v_self->_multithreaded);__pyx_v_self->_multithreaded = __pyx_v_6gevent_19_gevent_c_semaphore__MULTI;

     208:

     209:         # We conceptually now belong to the hub of the thread that

     210:         # called this, whether or not we have to block. Note that we

     211:         # cannot force it to be created yet, because Semaphore is used

     212:         # by importlib.ModuleLock which is used when importing the hub

     213:         # itself! This also checks for cross-thread issues.

    +214:         invalid_thread_use = None

    __Pyx_INCREF(Py_None);__pyx_v_invalid_thread_use = Py_None;

    +215:         try:

    {/*try:*/ {}__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;goto __pyx_L9_try_end;__pyx_L4_error:;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;__Pyx_XGIVEREF(__pyx_t_8);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_XGIVEREF(__pyx_t_10);__Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);goto __pyx_L1_error;__pyx_L7_except_return:;__Pyx_XGIVEREF(__pyx_t_8);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_XGIVEREF(__pyx_t_10);__Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);goto __pyx_L0;__pyx_L5_exception_handled:;__Pyx_XGIVEREF(__pyx_t_8);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_XGIVEREF(__pyx_t_10);__Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10);__pyx_L9_try_end:;}

    +216:             self._capture_hub(False)

    __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._capture_hub(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 216, __pyx_L4_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +217:         except InvalidThreadUseError as e:

    __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(__pyx_v_6gevent_19_gevent_c_semaphore_InvalidThreadUseError);if (__pyx_t_6) {__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.acquire", __pyx_clineno, __pyx_lineno, __pyx_filename);if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_1, &__pyx_t_4) < 0) __PYX_ERR(0, 217, __pyx_L6_except_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_GOTREF(__pyx_t_1);__Pyx_GOTREF(__pyx_t_4);__Pyx_INCREF(__pyx_t_1);__pyx_v_e = ((PyObject*)__pyx_t_1);/*try:*/ {/*finally:*/ {/*normal exit:*/{__Pyx_DECREF(__pyx_v_e); __pyx_v_e = 0;goto __pyx_L16;}__pyx_L15_error:;/*exception exit:*/{__Pyx_PyThreadState_declare__Pyx_PyThreadState_assign__pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16) < 0)) __Pyx_ErrFetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16);__Pyx_XGOTREF(__pyx_t_14);__Pyx_XGOTREF(__pyx_t_15);__Pyx_XGOTREF(__pyx_t_16);__Pyx_XGOTREF(__pyx_t_17);__Pyx_XGOTREF(__pyx_t_18);__Pyx_XGOTREF(__pyx_t_19);__pyx_t_6 = __pyx_lineno; __pyx_t_12 = __pyx_clineno; __pyx_t_13 = __pyx_filename;{__Pyx_DECREF(__pyx_v_e); __pyx_v_e = 0;}if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_17);__Pyx_XGIVEREF(__pyx_t_18);__Pyx_XGIVEREF(__pyx_t_19);__Pyx_ExceptionReset(__pyx_t_17, __pyx_t_18, __pyx_t_19);}__Pyx_XGIVEREF(__pyx_t_14);__Pyx_XGIVEREF(__pyx_t_15);__Pyx_XGIVEREF(__pyx_t_16);__Pyx_ErrRestore(__pyx_t_14, __pyx_t_15, __pyx_t_16);__pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0;__pyx_lineno = __pyx_t_6; __pyx_clineno = __pyx_t_12; __pyx_filename = __pyx_t_13;goto __pyx_L6_except_error;}__pyx_L14_return: {__pyx_t_7 = __pyx_r;__Pyx_DECREF(__pyx_v_e); __pyx_v_e = 0;__pyx_r = __pyx_t_7;goto __pyx_L7_except_return;}__pyx_L16:;}__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;goto __pyx_L5_exception_handled;}goto __pyx_L6_except_error;__pyx_L6_except_error:;

     218:             # My hub belongs to some other thread. We didn't release the GIL/object lock

     219:             # by raising the exception, so we know this is still true.

    +220:             invalid_thread_use = e.args

    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L15_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF_SET(__pyx_v_invalid_thread_use, __pyx_t_3);__pyx_t_3 = 0;

    +221:             e = None

    __Pyx_INCREF(Py_None);__Pyx_DECREF_SET(__pyx_v_e, ((PyObject*)Py_None));

    +222:             if not self.counter and blocking:

    __pyx_t_11 = (!(__pyx_v_self->counter != 0));if (__pyx_t_11) {} else {__pyx_t_7 = __pyx_t_11;goto __pyx_L18_bool_binop_done;}__pyx_t_7 = __pyx_v_blocking;__pyx_L18_bool_binop_done:;if (__pyx_t_7) {}}

     223:                 # We would need to block. So coordinate with the main hub.

    +224:                 return self.__acquire_from_other_thread(invalid_thread_use, blocking, timeout)

    if (!(likely(PyTuple_CheckExact(__pyx_v_invalid_thread_use))||((__pyx_v_invalid_thread_use) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_v_invalid_thread_use))) __PYX_ERR(0, 224, __pyx_L15_error)__pyx_t_3 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__acquire_from_other_thread(__pyx_v_self, ((PyObject*)__pyx_v_invalid_thread_use), __pyx_v_blocking, __pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L15_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 224, __pyx_L15_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_r = __pyx_t_7;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;goto __pyx_L14_return;

     225:

    +226:         if self.counter > 0:

    __pyx_t_7 = (__pyx_v_self->counter > 0);if (__pyx_t_7) {}

    +227:             self.counter -= 1

    __pyx_v_self->counter = (__pyx_v_self->counter - 1);

    +228:             return True

    __pyx_r = 1;goto __pyx_L0;

     229:

    +230:         if not blocking:

    __pyx_t_7 = (!__pyx_v_blocking);if (__pyx_t_7) {}

    +231:             return False

    __pyx_r = 0;goto __pyx_L0;

     232:

    +233:         if self._multithreaded is not _MULTI and self.hub is None: # pylint:disable=access-member-before-definition

    __pyx_t_11 = (__pyx_v_self->_multithreaded != __pyx_v_6gevent_19_gevent_c_semaphore__MULTI);if (__pyx_t_11) {} else {__pyx_t_7 = __pyx_t_11;goto __pyx_L27_bool_binop_done;}__pyx_t_11 = (((PyObject *)__pyx_v_self->__pyx_base.hub) == Py_None);__pyx_t_7 = __pyx_t_11;__pyx_L27_bool_binop_done:;if (__pyx_t_7) {}

    +234:             self.hub = get_hub() # pylint:disable=attribute-defined-outside-init

    __pyx_t_4 = ((PyObject *)__pyx_f_6gevent_19_gevent_c_hub_local_get_hub_noargs(0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 234, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_GIVEREF(__pyx_t_4);__Pyx_GOTREF((PyObject *)__pyx_v_self->__pyx_base.hub);__Pyx_DECREF((PyObject *)__pyx_v_self->__pyx_base.hub);__pyx_v_self->__pyx_base.hub = ((struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *)__pyx_t_4);__pyx_t_4 = 0;

     235:

    +236:         if self.hub is None and not invalid_thread_use:

    __pyx_t_11 = (((PyObject *)__pyx_v_self->__pyx_base.hub) == Py_None);if (__pyx_t_11) {} else {__pyx_t_7 = __pyx_t_11;goto __pyx_L30_bool_binop_done;}__pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_invalid_thread_use); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 236, __pyx_L1_error)__pyx_t_20 = (!__pyx_t_11);__pyx_t_7 = __pyx_t_20;__pyx_L30_bool_binop_done:;if (__pyx_t_7) {}

     237:             # Someone else is holding us. There's not a hub here,

     238:             # nor is there a hub in that thread. We'll need to use regular locks.

     239:             # This will be unfair to yet a third thread that tries to use us with greenlets.

    +240:             return self.__acquire_from_other_thread(

    __pyx_t_4 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__acquire_from_other_thread(__pyx_v_self, ((PyObject*)__pyx_t_1), __pyx_v_blocking, __pyx_v_timeout); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 240, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 240, __pyx_L1_error)__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;__pyx_r = __pyx_t_7;goto __pyx_L0;

    +241:                 (None, None, self._getcurrent(), "NoHubs"),

    __pyx_t_4 = ((PyObject *)((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._getcurrent(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 241, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 241, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_INCREF(Py_None);__Pyx_GIVEREF(Py_None);PyTuple_SET_ITEM(__pyx_t_1, 0, Py_None);__Pyx_INCREF(Py_None);__Pyx_GIVEREF(Py_None);PyTuple_SET_ITEM(__pyx_t_1, 1, Py_None);__Pyx_GIVEREF(__pyx_t_4);PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4);__Pyx_INCREF(__pyx_n_s_NoHubs);__Pyx_GIVEREF(__pyx_n_s_NoHubs);PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_NoHubs);__pyx_t_4 = 0;

     242:                 blocking,

     243:                 timeout

     244:             )

     245:

     246:         # self._wait may drop both the GIL and the _lock_lock.

     247:         # By the time we regain control, both have been reacquired.

    +248:         try:

    {/*try:*/ {}__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;goto __pyx_L37_try_end;__pyx_L32_error:;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;__Pyx_XGIVEREF(__pyx_t_10);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_XGIVEREF(__pyx_t_8);__Pyx_ExceptionReset(__pyx_t_10, __pyx_t_9, __pyx_t_8);goto __pyx_L1_error;__pyx_L35_except_return:;__Pyx_XGIVEREF(__pyx_t_10);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_XGIVEREF(__pyx_t_8);__Pyx_ExceptionReset(__pyx_t_10, __pyx_t_9, __pyx_t_8);goto __pyx_L0;__pyx_L33_exception_handled:;__Pyx_XGIVEREF(__pyx_t_10);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_XGIVEREF(__pyx_t_8);__Pyx_ExceptionReset(__pyx_t_10, __pyx_t_9, __pyx_t_8);__pyx_L37_try_end:;}

    +249:             success = self._wait(timeout)

    __pyx_t_21.__pyx_n = 1;__pyx_t_21.timeout = __pyx_v_timeout;__pyx_t_4 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._wait(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), &__pyx_t_21); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 249, __pyx_L32_error)__Pyx_GOTREF(__pyx_t_4);__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 249, __pyx_L32_error)__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;__pyx_v_success = __pyx_t_7;

    +250:         except LoopExit as ex:

    __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_v_6gevent_19_gevent_c_semaphore_LoopExit);if (__pyx_t_12) {__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.acquire", __pyx_clineno, __pyx_lineno, __pyx_filename);if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) __PYX_ERR(0, 250, __pyx_L34_except_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_GOTREF(__pyx_t_1);__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_t_1);__pyx_v_ex = ((PyObject*)__pyx_t_1);/*try:*/ {/*finally:*/ {/*normal exit:*/{__Pyx_DECREF(__pyx_v_ex); __pyx_v_ex = 0;goto __pyx_L44;}__pyx_L43_error:;/*exception exit:*/{__Pyx_PyThreadState_declare__Pyx_PyThreadState_assign__pyx_t_19 = 0; __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0;__Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14);if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17);__Pyx_XGOTREF(__pyx_t_19);__Pyx_XGOTREF(__pyx_t_18);__Pyx_XGOTREF(__pyx_t_17);__Pyx_XGOTREF(__pyx_t_16);__Pyx_XGOTREF(__pyx_t_15);__Pyx_XGOTREF(__pyx_t_14);__pyx_t_12 = __pyx_lineno; __pyx_t_6 = __pyx_clineno; __pyx_t_24 = __pyx_filename;{__Pyx_DECREF(__pyx_v_ex); __pyx_v_ex = 0;}if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_16);__Pyx_XGIVEREF(__pyx_t_15);__Pyx_XGIVEREF(__pyx_t_14);__Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14);}__Pyx_XGIVEREF(__pyx_t_19);__Pyx_XGIVEREF(__pyx_t_18);__Pyx_XGIVEREF(__pyx_t_17);__Pyx_ErrRestore(__pyx_t_19, __pyx_t_18, __pyx_t_17);__pyx_t_19 = 0; __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0;__pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_6; __pyx_filename = __pyx_t_24;goto __pyx_L34_except_error;}__pyx_L42_return: {__pyx_t_7 = __pyx_r;__Pyx_DECREF(__pyx_v_ex); __pyx_v_ex = 0;__pyx_r = __pyx_t_7;goto __pyx_L35_except_return;}__pyx_L44:;}__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;goto __pyx_L33_exception_handled;}goto __pyx_L34_except_error;__pyx_L34_except_error:;

    +251:             args = ex.args

    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ex, __pyx_n_s_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 251, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_3);if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_t_3))) __PYX_ERR(0, 251, __pyx_L43_error)__pyx_v_args = ((PyObject*)__pyx_t_3);__pyx_t_3 = 0;

    +252:             ex = None

    __Pyx_INCREF(Py_None);__Pyx_DECREF_SET(__pyx_v_ex, ((PyObject*)Py_None));

    +253:             if self.counter:

    __pyx_t_7 = (__pyx_v_self->counter != 0);if (__pyx_t_7) {goto __pyx_L45;}

    +254:                 success = True

    __pyx_v_success = 1;

     255:             else:

     256:                 # Avoid using ex.hub property to keep holding the GIL

    +257:                 if len(args) == 3 and args[1].main_hub:

    /*else*/ {if (unlikely(__pyx_v_args == Py_None)) {PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");__PYX_ERR(0, 257, __pyx_L43_error)}__pyx_t_22 = PyTuple_GET_SIZE(__pyx_v_args); if (unlikely(__pyx_t_22 == ((Py_ssize_t)-1))) __PYX_ERR(0, 257, __pyx_L43_error)__pyx_t_20 = (__pyx_t_22 == 3);if (__pyx_t_20) {} else {__pyx_t_7 = __pyx_t_20;goto __pyx_L47_bool_binop_done;}if (unlikely(__pyx_v_args == Py_None)) {PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");__PYX_ERR(0, 257, __pyx_L43_error)}__pyx_t_3 = __Pyx_GetItemInt_Tuple(__pyx_v_args, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 257, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_main_hub); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 257, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_5);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_20 < 0))) __PYX_ERR(0, 257, __pyx_L43_error)__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;__pyx_t_7 = __pyx_t_20;__pyx_L47_bool_binop_done:;if (unlikely(__pyx_t_7)) {}

     258:                     # The main hub, meaning the main thread. We probably can do nothing with this.

    +259:                     raise

    __Pyx_GIVEREF(__pyx_t_4);__Pyx_GIVEREF(__pyx_t_1);__Pyx_XGIVEREF(__pyx_t_2);__Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_1, __pyx_t_2);__pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; __PYX_ERR(0, 259, __pyx_L43_error)

    +260:                 return self.__acquire_from_other_thread(

    __pyx_t_3 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__acquire_from_other_thread(__pyx_v_self, ((PyObject*)__pyx_t_23), __pyx_v_blocking, __pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 260, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0;__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 260, __pyx_L43_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_r = __pyx_t_7;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;goto __pyx_L42_return;}__pyx_L45:;}

    +261:                     (self.hub, get_hub_if_exists(), self._getcurrent(), "LoopExit"),

    __pyx_t_5 = ((PyObject *)__pyx_f_6gevent_19_gevent_c_hub_local_get_hub_if_exists(0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 261, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_5);__pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._getcurrent(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 261, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_23 = PyTuple_New(4); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 261, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_23);__Pyx_INCREF((PyObject *)__pyx_v_self->__pyx_base.hub);__Pyx_GIVEREF((PyObject *)__pyx_v_self->__pyx_base.hub);PyTuple_SET_ITEM(__pyx_t_23, 0, ((PyObject *)__pyx_v_self->__pyx_base.hub));__Pyx_GIVEREF(__pyx_t_5);PyTuple_SET_ITEM(__pyx_t_23, 1, __pyx_t_5);__Pyx_GIVEREF(__pyx_t_3);PyTuple_SET_ITEM(__pyx_t_23, 2, __pyx_t_3);__Pyx_INCREF(__pyx_n_s_LoopExit);__Pyx_GIVEREF(__pyx_n_s_LoopExit);PyTuple_SET_ITEM(__pyx_t_23, 3, __pyx_n_s_LoopExit);__pyx_t_5 = 0;__pyx_t_3 = 0;

     262:                     blocking,

     263:                     timeout)

     264:

    +265:         if not success:

    __pyx_t_7 = (!__pyx_v_success);if (__pyx_t_7) {}

    +266:             assert timeout is not None

    #ifndef CYTHON_WITHOUT_ASSERTIONSif (unlikely(!Py_OptimizeFlag)) {__pyx_t_7 = (__pyx_v_timeout != Py_None);if (unlikely(!__pyx_t_7)) {__Pyx_Raise(__pyx_builtin_AssertionError, 0, 0, 0);__PYX_ERR(0, 266, __pyx_L1_error)}}#elseif ((1)); else __PYX_ERR(0, 266, __pyx_L1_error)#endif

     267:             # Our timer expired.

    +268:             return False

    __pyx_r = 0;goto __pyx_L0;

     269:

     270:         # Neither our timer or another one expired, so we blocked until

     271:         # awoke. Therefore, the counter is ours

    +272:         assert self.counter > 0, (self.counter, blocking, timeout, success,)

    #ifndef CYTHON_WITHOUT_ASSERTIONSif (unlikely(!Py_OptimizeFlag)) {__pyx_t_7 = (__pyx_v_self->counter > 0);if (unlikely(!__pyx_t_7)) {__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->counter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 272, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_blocking); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_success); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 272, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 272, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_GIVEREF(__pyx_t_2);PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);__Pyx_GIVEREF(__pyx_t_1);PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);__Pyx_INCREF(__pyx_v_timeout);__Pyx_GIVEREF(__pyx_v_timeout);PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_timeout);__Pyx_GIVEREF(__pyx_t_4);PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_4);__pyx_t_2 = 0;__pyx_t_1 = 0;__pyx_t_4 = 0;__pyx_t_4 = PyTuple_Pack(1, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 272, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_4, 0, 0);__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;__PYX_ERR(0, 272, __pyx_L1_error)}}#elseif ((1)); else __PYX_ERR(0, 272, __pyx_L1_error)#endif

    +273:         self.counter -= 1

    __pyx_v_self->counter = (__pyx_v_self->counter - 1);

    +274:         return True

    __pyx_r = 1;goto __pyx_L0;

     275:

    +276:     _py3k_acquire = acquire # PyPy needs this; it must be static for Cython

    __Pyx_GetNameInClass(__pyx_t_3, (PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_acquire); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 276, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_py3k_acquire, __pyx_t_3) < 0) __PYX_ERR(0, 276, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);

     277:

    +278:     def __enter__(self):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore___enter__(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__enter__", 0);/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_enter); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__)) {__Pyx_XDECREF(__pyx_r);__Pyx_INCREF(__pyx_t_1);__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 278, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_r = __pyx_t_2;__pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_r = Py_None; __Pyx_INCREF(Py_None);goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_16__enter__, "Semaphore.__enter__(self)");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__ = {"__enter__", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_16__enter__};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_16__enter__(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self));/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_16__enter__(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__enter__", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_1 = __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore___enter__(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore___enter, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__21)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 278, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_enter, __pyx_t_3) < 0) __PYX_ERR(0, 278, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_enter, 278, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 278, __pyx_L1_error)

    +279:         self.acquire()

    __pyx_t_6 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->acquire(__pyx_v_self, 0, NULL); if (unlikely(__pyx_t_6 == ((int)-1000))) __PYX_ERR(0, 279, __pyx_L1_error)

     280:

    +281:     def __exit__(self, t, v, tb):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore___exit__(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_t, CYTHON_UNUSED PyObject *__pyx_v_v, CYTHON_UNUSED PyObject *__pyx_v_tb, int __pyx_skip_dispatch) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__exit__", 0);/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_exit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__)) {__Pyx_XDECREF(__pyx_r);__Pyx_INCREF(__pyx_t_1);__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[4] = {__pyx_t_4, __pyx_v_t, __pyx_v_v, __pyx_v_tb};__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 3+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 281, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_r = __pyx_t_2;__pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_r = Py_None; __Pyx_INCREF(Py_None);goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_18__exit__, "Semaphore.__exit__(self, t, v, tb)");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__ = {"__exit__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_18__exit__};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {PyObject *__pyx_v_t = 0;PyObject *__pyx_v_v = 0;PyObject *__pyx_v_tb = 0;#if !CYTHON_METH_FASTCALLCYTHON_UNUSED const Py_ssize_t __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);#endifCYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);{#if CYTHON_USE_MODULE_STATEPyObject **__pyx_pyargnames[] = {&__pyx_n_s_t,&__pyx_n_s_v,&__pyx_n_s_tb,0};#elsestatic PyObject **__pyx_pyargnames[] = {&__pyx_n_s_t,&__pyx_n_s_v,&__pyx_n_s_tb,0};#endifPyObject* values[3] = {0,0,0};if (__pyx_kwds) {Py_ssize_t kw_args;switch (__pyx_nargs) {case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);CYTHON_FALLTHROUGH;case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);CYTHON_FALLTHROUGH;case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);switch (__pyx_nargs) {case  0:if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_t)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 281, __pyx_L3_error)else goto __pyx_L5_argtuple_error;CYTHON_FALLTHROUGH;case  1:if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_v)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 281, __pyx_L3_error)else {__Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 281, __pyx_L3_error)}CYTHON_FALLTHROUGH;case  2:if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tb)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 281, __pyx_L3_error)else {__Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 281, __pyx_L3_error)}}if (unlikely(kw_args > 0)) {const Py_ssize_t kwd_pos_args = __pyx_nargs;if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__exit__") < 0)) __PYX_ERR(0, 281, __pyx_L3_error)}} else if (unlikely(__pyx_nargs != 3)) {goto __pyx_L5_argtuple_error;} else {values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);}__pyx_v_t = values[0];__pyx_v_v = values[1];__pyx_v_tb = values[2];}goto __pyx_L4_argument_unpacking_done;__pyx_L5_argtuple_error:;__Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 281, __pyx_L3_error)__pyx_L3_error:;__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);__Pyx_RefNannyFinishContext();return NULL;__pyx_L4_argument_unpacking_done:;__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_18__exit__(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self), __pyx_v_t, __pyx_v_v, __pyx_v_tb);int __pyx_lineno = 0;const char *__pyx_filename = NULL;int __pyx_clineno = 0;/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_18__exit__(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_t, PyObject *__pyx_v_v, PyObject *__pyx_v_tb) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__exit__", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_1 = __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore___exit__(__pyx_v_self, __pyx_v_t, __pyx_v_v, __pyx_v_tb, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_tuple__22 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_t, __pyx_n_s_v, __pyx_n_s_tb); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 281, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__22);__Pyx_GIVEREF(__pyx_tuple__22);__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore___exit, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 281, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_exit, __pyx_t_3) < 0) __PYX_ERR(0, 281, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(4, 0, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_exit, 281, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 281, __pyx_L1_error)

    +282:         self.release()

    __pyx_t_5 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->release(__pyx_v_self, 0); if (unlikely(__pyx_t_5 == ((int)-1000))) __PYX_ERR(0, 282, __pyx_L1_error)

     283:

    +284:     def _handle_unswitched_notifications(self, unswitched):

    static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__handle_unswitched_notifications(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_unswitched) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_handle_unswitched_notifications", 0);/* function exit code */__pyx_r = Py_None; __Pyx_INCREF(Py_None);goto __pyx_L0;__pyx_L1_error:;__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._handle_unswitched_notifications", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}

     285:         # If we fail to switch to a greenlet in another thread to send

     286:         # a notification, just re-queue it, in the hopes that the

     287:         # other thread will eventually run notifications itself.

     288:         #

     289:         # We CANNOT do what the ``super()`` does and actually allow

     290:         # this notification to get run sometime in the future by

     291:         # scheduling a callback in the other thread. The algorithm

     292:         # that we use to handle cross-thread locking/unlocking was

     293:         # designed before the schedule-a-callback mechanism was

     294:         # implemented. If we allow this to be run as a callback, we

     295:         # can find ourself the victim of ``InvalidSwitchError`` (or

     296:         # worse, silent corruption) because the switch can come at an

     297:         # unexpected time: *after* the destination thread has already

     298:         # acquired the lock.

     299:         #

     300:         # This manifests in a fairly reliable test failure,

     301:         # ``gevent.tests.test__semaphore``

     302:         # ``TestSemaphoreMultiThread.test_dueling_threads_with_hub``,

     303:         # but ONLY when running in PURE_PYTHON mode.

     304:         #

     305:         # TODO: Maybe we can rewrite that part of the algorithm to be friendly to

     306:         # running the callbacks?

    +307:         self._links.extend(unswitched)

    if (unlikely(__pyx_v_self->__pyx_base._links == Py_None)) {PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "extend");__PYX_ERR(0, 307, __pyx_L1_error)}__pyx_t_1 = __Pyx_PyList_Extend(__pyx_v_self->__pyx_base._links, __pyx_v_unswitched); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 307, __pyx_L1_error)

     308:

    +309:     def __add_link(self, link):

    static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__Semaphore__add_link(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_link) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__add_link", 0);/* function exit code */__pyx_r = Py_None; __Pyx_INCREF(Py_None);goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__add_link", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}

    +310:         if not self._notifier:

    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->__pyx_base._notifier); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 310, __pyx_L1_error)__pyx_t_2 = (!__pyx_t_1);if (__pyx_t_2) {goto __pyx_L3;}

    +311:             self.rawlink(link)

    __pyx_t_3 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.rawlink(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), __pyx_v_link, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 311, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     312:         else:

    +313:             self._notifier.args[0].append(link)

    /*else*/ {__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base._notifier, __pyx_n_s_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 313, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 313, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_5 = __Pyx_PyObject_Append(__pyx_t_4, __pyx_v_link); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 313, __pyx_L1_error)__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;}__pyx_L3:;

     314:

    +315:     def __acquire_from_other_thread(self, ex_args, blocking, timeout):

    static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__Semaphore__acquire_from_other_thread(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_ex_args, int __pyx_v_blocking, PyObject *__pyx_v_timeout) {struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *__pyx_v_hub_for_this_thread = 0;struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *__pyx_v_owning_hub = 0;PyObject *__pyx_v_current_greenlet = NULL;PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__acquire_from_other_thread", 0);/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_from_other_thread", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XDECREF((PyObject *)__pyx_v_hub_for_this_thread);__Pyx_XDECREF((PyObject *)__pyx_v_owning_hub);__Pyx_XDECREF(__pyx_v_current_greenlet);__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}

    +316:         assert blocking

    #ifndef CYTHON_WITHOUT_ASSERTIONSif (unlikely(!Py_OptimizeFlag)) {if (unlikely(!__pyx_v_blocking)) {__Pyx_Raise(__pyx_builtin_AssertionError, 0, 0, 0);__PYX_ERR(0, 316, __pyx_L1_error)}}#elseif ((1)); else __PYX_ERR(0, 316, __pyx_L1_error)#endif

     317:         # Some other hub owns this object. We must ask it to wake us

     318:         # up. In general, we can't use a Python-level ``Lock`` because

     319:         #

     320:         # (1) it doesn't support a timeout on all platforms; and

     321:         # (2) we don't want to block this hub from running.

     322:         #

     323:         # So we need to do so in a way that cooperates with *two*

     324:         # hubs. That's what an async watcher is built for.

     325:         #

     326:         # Of course, if we don't actually have two hubs, then we must find some other

     327:         # solution. That involves using a lock.

     328:

     329:         # We have to take an action that drops the GIL and drops the object lock

     330:         # to allow the main thread (the thread for our hub) to advance.

    +331:         owning_hub = ex_args[0]

    if (unlikely(__pyx_v_ex_args == Py_None)) {PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");__PYX_ERR(0, 331, __pyx_L1_error)}__pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_ex_args, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 331, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop))))) __PYX_ERR(0, 331, __pyx_L1_error)__pyx_v_owning_hub = ((struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *)__pyx_t_1);__pyx_t_1 = 0;

    +332:         hub_for_this_thread = ex_args[1]

    if (unlikely(__pyx_v_ex_args == Py_None)) {PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");__PYX_ERR(0, 332, __pyx_L1_error)}__pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_ex_args, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 332, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop))))) __PYX_ERR(0, 332, __pyx_L1_error)__pyx_v_hub_for_this_thread = ((struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *)__pyx_t_1);__pyx_t_1 = 0;

    +333:         current_greenlet = ex_args[2]

    if (unlikely(__pyx_v_ex_args == Py_None)) {PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");__PYX_ERR(0, 333, __pyx_L1_error)}__pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_ex_args, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_v_current_greenlet = __pyx_t_1;__pyx_t_1 = 0;

     334:

    +335:         if owning_hub is None and hub_for_this_thread is None:

    __pyx_t_3 = (((PyObject *)__pyx_v_owning_hub) == Py_None);if (__pyx_t_3) {} else {__pyx_t_2 = __pyx_t_3;goto __pyx_L4_bool_binop_done;}__pyx_t_3 = (((PyObject *)__pyx_v_hub_for_this_thread) == Py_None);__pyx_t_2 = __pyx_t_3;__pyx_L4_bool_binop_done:;if (__pyx_t_2) {}

    +336:             return self.__acquire_without_hubs(timeout)

    __Pyx_XDECREF(__pyx_r);__pyx_t_1 = __Pyx_PyBool_FromLong(((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__acquire_without_hubs(__pyx_v_self, __pyx_v_timeout)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 336, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;

     337:

    +338:         if hub_for_this_thread is None:

    __pyx_t_2 = (((PyObject *)__pyx_v_hub_for_this_thread) == Py_None);if (__pyx_t_2) {}

     339:             # Probably a background worker thread. We don't want to create

     340:             # the hub if not needed, and since it didn't exist there are no

     341:             # other greenlets that we could yield to anyway, so there's nothing

     342:             # to block and no reason to try to avoid blocking, so using a native

     343:             # lock is the simplest way to go.

    +344:             return self.__acquire_using_other_hub(owning_hub, timeout)

    __Pyx_XDECREF(__pyx_r);__pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__acquire_using_other_hub(__pyx_v_self, __pyx_v_owning_hub, __pyx_v_timeout); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 344, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;

     345:

     346:         # We have a hub we don't want to block. Use an async watcher

     347:         # and ask the next releaser of this object to wake us up.

    +348:         return self.__acquire_using_two_hubs(hub_for_this_thread,

    __Pyx_XDECREF(__pyx_r);__pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__acquire_using_two_hubs(__pyx_v_self, __pyx_v_hub_for_this_thread, __pyx_v_current_greenlet, __pyx_v_timeout); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 348, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;

     349:                                              current_greenlet,

     350:                                              timeout)

     351:

    +352:     def __acquire_using_two_hubs(self,

    static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__Semaphore__acquire_using_two_hubs(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *__pyx_v_hub_for_this_thread, PyObject *__pyx_v_current_greenlet, PyObject *__pyx_v_timeout) {PyObject *__pyx_v_watcher = NULL;PyObject *__pyx_v_send = NULL;PyObject *__pyx_v_timer = NULL;int __pyx_v_result;PyObject *__pyx_v_tex = NULL;PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__acquire_using_two_hubs", 0);/* function exit code */__pyx_r = Py_None; __Pyx_INCREF(Py_None);goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_5);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_using_two_hubs", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XDECREF(__pyx_v_watcher);__Pyx_XDECREF(__pyx_v_send);__Pyx_XDECREF(__pyx_v_timer);__Pyx_XDECREF(__pyx_v_tex);__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}

     353:                                  hub_for_this_thread,

     354:                                  current_greenlet,

     355:                                  timeout):

     356:         # Allocating and starting the watcher *could* release the GIL.

     357:         # with the libev corcext, allocating won't, but starting briefly will.

     358:         # With other backends, allocating might, and starting might also.

     359:         # So...

    +360:         watcher = hub_for_this_thread.loop.async_()

    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_hub_for_this_thread->loop, __pyx_n_s_async); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 360, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_3 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_3, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 360, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__pyx_v_watcher = __pyx_t_1;__pyx_t_1 = 0;

    +361:         send = watcher.send_ignoring_arg

    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_send_ignoring_arg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 361, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_v_send = __pyx_t_1;__pyx_t_1 = 0;

    +362:         watcher.start(current_greenlet.switch, self)

    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_current_greenlet, __pyx_n_s_switch); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_5 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_5)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_5);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_t_3, ((PyObject *)__pyx_v_self)};__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 2+__pyx_t_4);__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 362, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +363:         try:

    /*try:*/ {

    +364:             with Timeout._start_new_or_dummy(timeout) as timer:

    /*with:*/ {__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_6gevent_19_gevent_c_semaphore_Timeout, __pyx_n_s_start_new_or_dummy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 364, __pyx_L4_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_3 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_timeout};__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L4_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 364, __pyx_L4_error)__Pyx_GOTREF(__pyx_t_6);__pyx_t_3 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_n_s_enter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 364, __pyx_L6_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_5 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_5)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_5);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_5, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 364, __pyx_L6_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_t_3 = __pyx_t_2;__pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;/*try:*/ {{/*try:*/ {__pyx_v_timer = __pyx_t_3;__pyx_t_3 = 0;}__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;goto __pyx_L15_try_end;__pyx_L10_error:;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;/*except:*/ {__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_using_two_hubs", __pyx_clineno, __pyx_lineno, __pyx_filename);if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_1) < 0) __PYX_ERR(0, 364, __pyx_L12_except_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_GOTREF(__pyx_t_3);__Pyx_GOTREF(__pyx_t_1);__pyx_t_5 = PyTuple_Pack(3, __pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 364, __pyx_L12_except_error)__Pyx_GOTREF(__pyx_t_5);__pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL);__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 364, __pyx_L12_except_error)__Pyx_GOTREF(__pyx_t_12);__pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_12);__Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;if (__pyx_t_13 < 0) __PYX_ERR(0, 364, __pyx_L12_except_error)__pyx_t_23 = (!__pyx_t_13);if (unlikely(__pyx_t_23)) {__Pyx_GIVEREF(__pyx_t_2);__Pyx_GIVEREF(__pyx_t_3);__Pyx_XGIVEREF(__pyx_t_1);__Pyx_ErrRestoreWithState(__pyx_t_2, __pyx_t_3, __pyx_t_1);__pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_1 = 0; __PYX_ERR(0, 364, __pyx_L12_except_error)}__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L11_exception_handled;}__pyx_L12_except_error:;__Pyx_XGIVEREF(__pyx_t_7);__Pyx_XGIVEREF(__pyx_t_8);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);goto __pyx_L4_error;__pyx_L14_try_return:;__Pyx_XGIVEREF(__pyx_t_7);__Pyx_XGIVEREF(__pyx_t_8);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);goto __pyx_L7_return;__pyx_L11_exception_handled:;__Pyx_XGIVEREF(__pyx_t_7);__Pyx_XGIVEREF(__pyx_t_8);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);__pyx_L15_try_end:;}}/*finally:*/ {/*normal exit:*/{if (__pyx_t_6) {__pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__4, NULL);__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 364, __pyx_L4_error)__Pyx_GOTREF(__pyx_t_9);__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;}goto __pyx_L9;}__pyx_L7_return: {__pyx_t_9 = __pyx_r;__pyx_r = 0;if (__pyx_t_6) {__pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__4, NULL);__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 364, __pyx_L4_error)__Pyx_GOTREF(__pyx_t_8);__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;}__pyx_r = __pyx_t_9;__pyx_t_9 = 0;goto __pyx_L3_return;}__pyx_L9:;}goto __pyx_L41;__pyx_L6_error:;__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;goto __pyx_L4_error;__pyx_L41:;}}__pyx_tuple__4 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 364, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__4);__Pyx_GIVEREF(__pyx_tuple__4);

     365:                 # ... now that we're back holding the GIL, we need to verify our

     366:                 # state.

    +367:                 try:

    {/*try:*/ {}__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;__Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;__Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;goto __pyx_L21_try_end;__pyx_L16_error:;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;__Pyx_XGIVEREF(__pyx_t_10);__Pyx_XGIVEREF(__pyx_t_11);__Pyx_XGIVEREF(__pyx_t_12);__Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);goto __pyx_L10_error;__pyx_L20_try_return:;__Pyx_XGIVEREF(__pyx_t_10);__Pyx_XGIVEREF(__pyx_t_11);__Pyx_XGIVEREF(__pyx_t_12);__Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);goto __pyx_L14_try_return;__pyx_L19_except_return:;__Pyx_XGIVEREF(__pyx_t_10);__Pyx_XGIVEREF(__pyx_t_11);__Pyx_XGIVEREF(__pyx_t_12);__Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);goto __pyx_L14_try_return;__pyx_L21_try_end:;}

    +368:                     while 1:

    while (1) {

    +369:                         if self.counter > 0:

    __pyx_t_13 = (__pyx_v_self->counter > 0);if (__pyx_t_13) {}

    +370:                             self.counter -= 1

    __pyx_v_self->counter = (__pyx_v_self->counter - 1);

    +371:                             assert self.counter >= 0, (self,)

    #ifndef CYTHON_WITHOUT_ASSERTIONSif (unlikely(!Py_OptimizeFlag)) {__pyx_t_13 = (__pyx_v_self->counter >= 0);if (unlikely(!__pyx_t_13)) {__pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 371, __pyx_L16_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF((PyObject *)__pyx_v_self);__Pyx_GIVEREF((PyObject *)__pyx_v_self);PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self));__pyx_t_1 = PyTuple_Pack(1, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L16_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_1, 0, 0);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__PYX_ERR(0, 371, __pyx_L16_error)}}#elseif ((1)); else __PYX_ERR(0, 371, __pyx_L16_error)#endif

    +372:                             return True

    __Pyx_XDECREF(__pyx_r);__Pyx_INCREF(Py_True);__pyx_r = Py_True;goto __pyx_L20_try_return;

     373:

    +374:                         self.__add_link(send)

    __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__add_link(__pyx_v_self, __pyx_v_send); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __pyx_L16_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     375:

     376:                         # Releases the object lock

    +377:                         self._switch_to_hub(hub_for_this_thread)

    __pyx_t_4 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._switch_to_hub(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), ((PyObject *)__pyx_v_hub_for_this_thread)); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 377, __pyx_L16_error)

     378:                         # We waited and got notified. We should be ready now, so a non-blocking

     379:                         # acquire() should succeed. But sometimes we get spurious notifications?

     380:                         # It's not entirely clear how. So we need to loop until we get it, or until

     381:                         # the timer expires

    +382:                         result = self.acquire(0)

    __pyx_t_14.__pyx_n = 1;__pyx_t_14.blocking = 0;__pyx_t_13 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->acquire(__pyx_v_self, 0, &__pyx_t_14); if (unlikely(__pyx_t_13 == ((int)-1000))) __PYX_ERR(0, 382, __pyx_L16_error)__pyx_v_result = __pyx_t_13;

    +383:                         if result:

    if (__pyx_v_result) {}}

    +384:                             return result

    __Pyx_XDECREF(__pyx_r);__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 384, __pyx_L16_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L20_try_return;

    +385:                 except Timeout as tex:

    __pyx_t_4 = __Pyx_PyErr_ExceptionMatches(__pyx_v_6gevent_19_gevent_c_semaphore_Timeout);if (__pyx_t_4) {__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_using_two_hubs", __pyx_clineno, __pyx_lineno, __pyx_filename);if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_3, &__pyx_t_2) < 0) __PYX_ERR(0, 385, __pyx_L18_except_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_GOTREF(__pyx_t_3);__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF(__pyx_t_3);__pyx_v_tex = __pyx_t_3;/*try:*/ {/*finally:*/ {__pyx_L31_error:;/*exception exit:*/{__Pyx_PyThreadState_declare__Pyx_PyThreadState_assign__pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_21, &__pyx_t_22);if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19) < 0)) __Pyx_ErrFetch(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);__Pyx_XGOTREF(__pyx_t_17);__Pyx_XGOTREF(__pyx_t_18);__Pyx_XGOTREF(__pyx_t_19);__Pyx_XGOTREF(__pyx_t_20);__Pyx_XGOTREF(__pyx_t_21);__Pyx_XGOTREF(__pyx_t_22);__pyx_t_4 = __pyx_lineno; __pyx_t_15 = __pyx_clineno; __pyx_t_16 = __pyx_filename;{__Pyx_DECREF(__pyx_v_tex); __pyx_v_tex = 0;}if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_20);__Pyx_XGIVEREF(__pyx_t_21);__Pyx_XGIVEREF(__pyx_t_22);__Pyx_ExceptionReset(__pyx_t_20, __pyx_t_21, __pyx_t_22);}__Pyx_XGIVEREF(__pyx_t_17);__Pyx_XGIVEREF(__pyx_t_18);__Pyx_XGIVEREF(__pyx_t_19);__Pyx_ErrRestore(__pyx_t_17, __pyx_t_18, __pyx_t_19);__pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0;__pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_15; __pyx_filename = __pyx_t_16;goto __pyx_L18_except_error;}__pyx_L30_return: {__pyx_t_22 = __pyx_r;__pyx_r = 0;__Pyx_DECREF(__pyx_v_tex); __pyx_v_tex = 0;__pyx_r = __pyx_t_22;__pyx_t_22 = 0;goto __pyx_L19_except_return;}}}goto __pyx_L18_except_error;__pyx_L18_except_error:;

    +386:                     if tex is not timer:

    __pyx_t_13 = (__pyx_v_tex != __pyx_v_timer);if (unlikely(__pyx_t_13)) {}

    +387:                         raise

    __Pyx_GIVEREF(__pyx_t_1);__Pyx_GIVEREF(__pyx_t_3);__Pyx_XGIVEREF(__pyx_t_2);__Pyx_ErrRestoreWithState(__pyx_t_1, __pyx_t_3, __pyx_t_2);__pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_2 = 0; __PYX_ERR(0, 387, __pyx_L31_error)

    +388:                     return False

    __Pyx_XDECREF(__pyx_r);__Pyx_INCREF(Py_False);__pyx_r = Py_False;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;goto __pyx_L30_return;}

     389:         finally:

    +390:             self._quiet_unlink_all(send)

    /*finally:*/ {/*normal exit:*/{((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._quiet_unlink_all(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), __pyx_v_send);((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._quiet_unlink_all(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), __pyx_v_send);((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._quiet_unlink_all(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), __pyx_v_send);

    +391:             watcher.stop()

    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_2 = NULL;__pyx_t_15 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_2)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_2);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_15 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_2, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_15, 0+__pyx_t_15);__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 391, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_2 = NULL;__pyx_t_25 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_2)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_2);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_25 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_2, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_25, 0+__pyx_t_25);__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 391, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_2 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_2)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_2);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_2, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 391, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +392:             watcher.close()

    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_2 = NULL;__pyx_t_15 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_2)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_2);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_15 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_2, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_15, 0+__pyx_t_15);__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L5;}__pyx_L4_error:;/*exception exit:*/{__Pyx_PyThreadState_declare__Pyx_PyThreadState_assign__pyx_t_6 = 0; __pyx_t_9 = 0; __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_7, &__pyx_t_12, &__pyx_t_11);if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_9, &__pyx_t_8) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_9, &__pyx_t_8);__Pyx_XGOTREF(__pyx_t_6);__Pyx_XGOTREF(__pyx_t_9);__Pyx_XGOTREF(__pyx_t_8);__Pyx_XGOTREF(__pyx_t_7);__Pyx_XGOTREF(__pyx_t_12);__Pyx_XGOTREF(__pyx_t_11);__pyx_t_15 = __pyx_lineno; __pyx_t_4 = __pyx_clineno; __pyx_t_24 = __pyx_filename;{__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_2 = NULL;__pyx_t_25 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_2)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_2);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_25 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_2, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_25, 0+__pyx_t_25);__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L43_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;}if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_7);__Pyx_XGIVEREF(__pyx_t_12);__Pyx_XGIVEREF(__pyx_t_11);__Pyx_ExceptionReset(__pyx_t_7, __pyx_t_12, __pyx_t_11);}__Pyx_XGIVEREF(__pyx_t_6);__Pyx_XGIVEREF(__pyx_t_9);__Pyx_XGIVEREF(__pyx_t_8);__Pyx_ErrRestore(__pyx_t_6, __pyx_t_9, __pyx_t_8);__pyx_t_6 = 0; __pyx_t_9 = 0; __pyx_t_8 = 0; __pyx_t_7 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0;__pyx_lineno = __pyx_t_15; __pyx_clineno = __pyx_t_4; __pyx_filename = __pyx_t_24;goto __pyx_L1_error;__pyx_L43_error:;if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_7);__Pyx_XGIVEREF(__pyx_t_12);__Pyx_XGIVEREF(__pyx_t_11);__Pyx_ExceptionReset(__pyx_t_7, __pyx_t_12, __pyx_t_11);}__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;__pyx_t_7 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0;goto __pyx_L1_error;}__pyx_L3_return: {__pyx_t_11 = __pyx_r;__pyx_r = 0;__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_2 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_2)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_2);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_2, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__pyx_r = __pyx_t_11;__pyx_t_11 = 0;goto __pyx_L0;}__pyx_L5:;}

     393:

    +394:     def __acquire_from_other_thread_cb(self, results, blocking, timeout, thread_lock):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__Semaphore__acquire_from_other_thread_cb(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_results, int __pyx_v_blocking, PyObject *__pyx_v_timeout, PyObject *__pyx_v_thread_lock, int __pyx_skip_dispatch) {int __pyx_v_result;PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__acquire_from_other_thread_cb", 0);/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_Semaphore__acquire_from_other_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb)) {__Pyx_XDECREF(__pyx_r);__pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_blocking); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF(__pyx_t_1);__pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL;__pyx_t_6 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {__pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);if (likely(__pyx_t_5)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);__Pyx_INCREF(__pyx_t_5);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_4, function);__pyx_t_6 = 1;}}{PyObject *__pyx_callargs[5] = {__pyx_t_5, __pyx_v_results, __pyx_t_3, __pyx_v_timeout, __pyx_v_thread_lock};__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 4+__pyx_t_6);__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 394, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;}__pyx_r = __pyx_t_2;__pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_XDECREF(__pyx_t_5);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_from_other_thread_cb", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_20_Semaphore__acquire_from_other_thread_cb, "Semaphore.__acquire_from_other_thread_cb(self, list results, bool blocking, timeout, thread_lock)");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb = {"_Semaphore__acquire_from_other_thread_cb", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_20_Semaphore__acquire_from_other_thread_cb};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {PyObject *__pyx_v_results = 0;int __pyx_v_blocking;PyObject *__pyx_v_timeout = 0;PyObject *__pyx_v_thread_lock = 0;#if !CYTHON_METH_FASTCALLCYTHON_UNUSED const Py_ssize_t __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);#endifCYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__acquire_from_other_thread_cb (wrapper)", 0);{#if CYTHON_USE_MODULE_STATEPyObject **__pyx_pyargnames[] = {&__pyx_n_s_results,&__pyx_n_s_blocking,&__pyx_n_s_timeout,&__pyx_n_s_thread_lock,0};#elsestatic PyObject **__pyx_pyargnames[] = {&__pyx_n_s_results,&__pyx_n_s_blocking,&__pyx_n_s_timeout,&__pyx_n_s_thread_lock,0};#endifPyObject* values[4] = {0,0,0,0};if (__pyx_kwds) {Py_ssize_t kw_args;switch (__pyx_nargs) {case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);CYTHON_FALLTHROUGH;case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);CYTHON_FALLTHROUGH;case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);CYTHON_FALLTHROUGH;case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);CYTHON_FALLTHROUGH;case  0: break;default: goto __pyx_L5_argtuple_error;}kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);switch (__pyx_nargs) {case  0:if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_results)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L3_error)else goto __pyx_L5_argtuple_error;CYTHON_FALLTHROUGH;case  1:if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_blocking)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L3_error)else {__Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, 1); __PYX_ERR(0, 394, __pyx_L3_error)}CYTHON_FALLTHROUGH;case  2:if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_timeout)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L3_error)else {__Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, 2); __PYX_ERR(0, 394, __pyx_L3_error)}CYTHON_FALLTHROUGH;case  3:if (likely((values[3] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_thread_lock)) != 0)) kw_args--;else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L3_error)else {__Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, 3); __PYX_ERR(0, 394, __pyx_L3_error)}}if (unlikely(kw_args > 0)) {const Py_ssize_t kwd_pos_args = __pyx_nargs;if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "_Semaphore__acquire_from_other_thread_cb") < 0)) __PYX_ERR(0, 394, __pyx_L3_error)}} else if (unlikely(__pyx_nargs != 4)) {goto __pyx_L5_argtuple_error;} else {values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);}__pyx_v_results = ((PyObject*)values[0]);__pyx_v_blocking = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_blocking == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L3_error)__pyx_v_timeout = values[2];__pyx_v_thread_lock = values[3];}goto __pyx_L4_argument_unpacking_done;__pyx_L5_argtuple_error:;__Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, __pyx_nargs); __PYX_ERR(0, 394, __pyx_L3_error)__pyx_L3_error:;__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_from_other_thread_cb", __pyx_clineno, __pyx_lineno, __pyx_filename);__Pyx_RefNannyFinishContext();return NULL;__pyx_L4_argument_unpacking_done:;if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_results), (&PyList_Type), 1, "results", 1))) __PYX_ERR(0, 394, __pyx_L1_error)__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_20_Semaphore__acquire_from_other_thread_cb(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self), __pyx_v_results, __pyx_v_blocking, __pyx_v_timeout, __pyx_v_thread_lock);int __pyx_lineno = 0;const char *__pyx_filename = NULL;int __pyx_clineno = 0;/* function exit code */goto __pyx_L0;__pyx_L1_error:;__pyx_r = NULL;__pyx_L0:;__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_9Semaphore_20_Semaphore__acquire_from_other_thread_cb(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_results, int __pyx_v_blocking, PyObject *__pyx_v_timeout, PyObject *__pyx_v_thread_lock) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__acquire_from_other_thread_cb", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_1 = __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__Semaphore__acquire_from_other_thread_cb(__pyx_v_self, __pyx_v_results, __pyx_v_blocking, __pyx_v_timeout, __pyx_v_thread_lock, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_from_other_thread_cb", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_tuple__24 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_results, __pyx_n_s_blocking, __pyx_n_s_timeout, __pyx_n_s_thread_lock); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 394, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__24);__Pyx_GIVEREF(__pyx_tuple__24);__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore__Semaphore__acquire_fr, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__25)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 394, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore->tp_dict, __pyx_n_s_Semaphore__acquire_from_other_t, __pyx_t_3) < 0) __PYX_ERR(0, 394, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);__pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(5, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_Semaphore__acquire_from_other_t, 394, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 394, __pyx_L1_error)

    +395:         try:

    /*try:*/ {

    +396:             result = self.acquire(blocking, timeout)

    __pyx_t_8.__pyx_n = 2;__pyx_t_8.blocking = __pyx_v_blocking;__pyx_t_8.timeout = __pyx_v_timeout;__pyx_t_7 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->acquire(__pyx_v_self, 0, &__pyx_t_8); if (unlikely(__pyx_t_7 == ((int)-1000))) __PYX_ERR(0, 396, __pyx_L4_error)__pyx_v_result = __pyx_t_7;

    +397:             results.append(result)

    if (unlikely(__pyx_v_results == Py_None)) {PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append");__PYX_ERR(0, 397, __pyx_L4_error)}__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 397, __pyx_L4_error)__Pyx_GOTREF(__pyx_t_1);__pyx_t_9 = __Pyx_PyList_Append(__pyx_v_results, __pyx_t_1); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 397, __pyx_L4_error)__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;}

     398:         finally:

    +399:             thread_lock.release()

    /*finally:*/ {/*normal exit:*/{__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_release); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_4 = NULL;__pyx_t_6 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_6 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L5;}__pyx_L4_error:;/*exception exit:*/{__Pyx_PyThreadState_declare__Pyx_PyThreadState_assign__pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0;__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14) < 0)) __Pyx_ErrFetch(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);__Pyx_XGOTREF(__pyx_t_12);__Pyx_XGOTREF(__pyx_t_13);__Pyx_XGOTREF(__pyx_t_14);__Pyx_XGOTREF(__pyx_t_15);__Pyx_XGOTREF(__pyx_t_16);__Pyx_XGOTREF(__pyx_t_17);__pyx_t_6 = __pyx_lineno; __pyx_t_10 = __pyx_clineno; __pyx_t_11 = __pyx_filename;{__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_release); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L7_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_4 = NULL;__pyx_t_18 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_18 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_18, 0+__pyx_t_18);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L7_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;}if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_15);__Pyx_XGIVEREF(__pyx_t_16);__Pyx_XGIVEREF(__pyx_t_17);__Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);}__Pyx_XGIVEREF(__pyx_t_12);__Pyx_XGIVEREF(__pyx_t_13);__Pyx_XGIVEREF(__pyx_t_14);__Pyx_ErrRestore(__pyx_t_12, __pyx_t_13, __pyx_t_14);__pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0;__pyx_lineno = __pyx_t_6; __pyx_clineno = __pyx_t_10; __pyx_filename = __pyx_t_11;goto __pyx_L1_error;__pyx_L7_error:;if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_15);__Pyx_XGIVEREF(__pyx_t_16);__Pyx_XGIVEREF(__pyx_t_17);__Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);}__Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;__Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;__Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;__pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0;goto __pyx_L1_error;}__pyx_L5:;}

    +400:         return result

    __Pyx_XDECREF(__pyx_r);__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 400, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;

     401:

    +402:     def __acquire_using_other_hub(self, owning_hub, timeout):

    static PyObject *__pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__Semaphore__acquire_using_other_hub(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *__pyx_v_owning_hub, PyObject *__pyx_v_timeout) {PyObject *__pyx_v_thread_lock = NULL;PyObject *__pyx_v_results = NULL;PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__acquire_using_other_hub", 0);/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_XDECREF(__pyx_t_6);__Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_using_other_hub", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = 0;__pyx_L0:;__Pyx_XDECREF(__pyx_v_thread_lock);__Pyx_XDECREF(__pyx_v_results);__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}

    +403:         assert owning_hub is not get_hub_if_exists()

    #ifndef CYTHON_WITHOUT_ASSERTIONSif (unlikely(!Py_OptimizeFlag)) {__pyx_t_1 = ((PyObject *)__pyx_f_6gevent_19_gevent_c_hub_local_get_hub_if_exists(0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_t_2 = (__pyx_v_owning_hub != ((struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *)__pyx_t_1));__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;if (unlikely(!__pyx_t_2)) {__Pyx_Raise(__pyx_builtin_AssertionError, 0, 0, 0);__PYX_ERR(0, 403, __pyx_L1_error)}}#elseif ((1)); else __PYX_ERR(0, 403, __pyx_L1_error)#endif

    +404:         thread_lock = self._allocate_lock()

    __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._allocate_lock(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 404, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_v_thread_lock = __pyx_t_1;__pyx_t_1 = 0;

    +405:         thread_lock.acquire()

    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_acquire); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 405, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 405, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +406:         results = []

    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 406, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_v_results = ((PyObject*)__pyx_t_1);__pyx_t_1 = 0;

     407:

    +408:         owning_hub.loop.run_callback_threadsafe(

    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_owning_hub->loop, __pyx_n_s_run_callback_threadsafe); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 408, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);

     409:             spawn_raw,

    +410:             self.__acquire_from_other_thread_cb,

    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_Semaphore__acquire_from_other_t); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 410, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);

     411:             results,

     412:             1,       # blocking,

     413:             timeout, # timeout,

    +414:             thread_lock)

    __pyx_t_6 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {__pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_6)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_6);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[7] = {__pyx_t_6, __pyx_v_6gevent_19_gevent_c_semaphore_spawn_raw, __pyx_t_4, __pyx_v_results, __pyx_int_1, __pyx_v_timeout, __pyx_v_thread_lock};__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 6+__pyx_t_5);__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 408, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     415:

     416:         # We MUST use a blocking acquire here, or at least be sure we keep going

     417:         # until we acquire it. If we timed out waiting here,

     418:         # just before the callback runs, then we would be out of sync.

    +419:         self.__spin_on_native_lock(thread_lock, None)

    (void)(((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__spin_on_native_lock(__pyx_v_self, __pyx_v_thread_lock, Py_None));

    +420:         return results[0]

    __Pyx_XDECREF(__pyx_r);__pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_results, 0, long, 1, __Pyx_PyInt_From_long, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 420, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_r = __pyx_t_1;__pyx_t_1 = 0;goto __pyx_L0;

     421:

    +422:     def __acquire_without_hubs(self, timeout):

    static int __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__Semaphore__acquire_without_hubs(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_timeout) {PyObject *__pyx_v_thread_lock = NULL;PyObject *__pyx_v_absolute_expiration = NULL;PyObject *__pyx_v_begin = NULL;struct __pyx_obj_6gevent_19_gevent_c_semaphore__LockReleaseLink *__pyx_v_link = NULL;int __pyx_v_got_native;PyObject *__pyx_v_now = NULL;PyObject *__pyx_v_duration = NULL;int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__acquire_without_hubs", 0);__Pyx_INCREF(__pyx_v_timeout);/* function exit code */__pyx_r = 0;goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_WriteUnraisable("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_without_hubs", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);__pyx_r = 0;__pyx_L0:;__Pyx_XDECREF(__pyx_v_thread_lock);__Pyx_XDECREF(__pyx_v_absolute_expiration);__Pyx_XDECREF(__pyx_v_begin);__Pyx_XDECREF((PyObject *)__pyx_v_link);__Pyx_XDECREF(__pyx_v_now);__Pyx_XDECREF(__pyx_v_duration);__Pyx_XDECREF(__pyx_v_timeout);__Pyx_RefNannyFinishContext();return __pyx_r;}

    +423:         thread_lock = self._allocate_lock()

    __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._allocate_lock(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 423, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_v_thread_lock = __pyx_t_1;__pyx_t_1 = 0;

    +424:         thread_lock.acquire()

    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_acquire); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 424, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_3 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_3, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 424, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +425:         absolute_expiration = 0

    __Pyx_INCREF(__pyx_int_0);__pyx_v_absolute_expiration = __pyx_int_0;

    +426:         begin = 0

    __Pyx_INCREF(__pyx_int_0);__pyx_v_begin = __pyx_int_0;

    +427:         if timeout:

    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_timeout); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 427, __pyx_L1_error)if (__pyx_t_5) {}

    +428:             absolute_expiration = monotonic() + timeout

    __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);__pyx_t_2 = __pyx_v_6gevent_19_gevent_c_semaphore_monotonic; __pyx_t_3 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_3, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 428, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_timeout); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 428, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_DECREF_SET(__pyx_v_absolute_expiration, __pyx_t_2);__pyx_t_2 = 0;

     429:

     430:         # Cython won't compile a lambda here

    +431:         link = _LockReleaseLink(thread_lock)

    __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore__LockReleaseLink), __pyx_v_thread_lock); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 431, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_v_link = ((struct __pyx_obj_6gevent_19_gevent_c_semaphore__LockReleaseLink *)__pyx_t_2);__pyx_t_2 = 0;

    +432:         while 1:

    while (1) {

    +433:             self.__add_link(link)

    __pyx_t_2 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__add_link(__pyx_v_self, ((PyObject *)__pyx_v_link)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 433, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +434:             if absolute_expiration:

    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_absolute_expiration); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 434, __pyx_L1_error)if (__pyx_t_5) {}

    +435:                 begin = monotonic()

    __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);__pyx_t_1 = __pyx_v_6gevent_19_gevent_c_semaphore_monotonic; __pyx_t_3 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_1, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_3, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;}__Pyx_DECREF_SET(__pyx_v_begin, __pyx_t_2);__pyx_t_2 = 0;

     436:

    +437:             got_native = self.__spin_on_native_lock(thread_lock, timeout)

    __pyx_v_got_native = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__spin_on_native_lock(__pyx_v_self, __pyx_v_thread_lock, __pyx_v_timeout);

    +438:             self._quiet_unlink_all(link)

    ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._quiet_unlink_all(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), ((PyObject *)__pyx_v_link));

    +439:             if got_native:

    if (__pyx_v_got_native) {}

    +440:                 if self.acquire(0):

    __pyx_t_6.__pyx_n = 1;__pyx_t_6.blocking = 0;__pyx_t_5 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->acquire(__pyx_v_self, 0, &__pyx_t_6); if (unlikely(__pyx_t_5 == ((int)-1000))) __PYX_ERR(0, 440, __pyx_L1_error)if (__pyx_t_5) {}

    +441:                     return True

    __pyx_r = 1;goto __pyx_L0;

    +442:             if absolute_expiration:

    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_absolute_expiration); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 442, __pyx_L1_error)if (__pyx_t_5) {}}

    +443:                 now = monotonic()

    __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);__pyx_t_1 = __pyx_v_6gevent_19_gevent_c_semaphore_monotonic; __pyx_t_3 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_1, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_3, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 443, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;}__Pyx_XDECREF_SET(__pyx_v_now, __pyx_t_2);__pyx_t_2 = 0;

    +444:                 if now >= absolute_expiration:

    __pyx_t_2 = PyObject_RichCompare(__pyx_v_now, __pyx_v_absolute_expiration, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 444, __pyx_L1_error)__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 444, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;if (__pyx_t_5) {}

    +445:                     return False

    __pyx_r = 0;goto __pyx_L0;

    +446:                 duration = now - begin

    __pyx_t_2 = PyNumber_Subtract(__pyx_v_now, __pyx_v_begin); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_XDECREF_SET(__pyx_v_duration, __pyx_t_2);__pyx_t_2 = 0;

    +447:                 timeout -= duration

    __pyx_t_2 = PyNumber_InPlaceSubtract(__pyx_v_timeout, __pyx_v_duration); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 447, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF_SET(__pyx_v_timeout, __pyx_t_2);__pyx_t_2 = 0;

    +448:                 if timeout <= 0:

    __pyx_t_2 = PyObject_RichCompare(__pyx_v_timeout, __pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 448, __pyx_L1_error)__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 448, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;if (__pyx_t_5) {}

    +449:                     return False

    __pyx_r = 0;goto __pyx_L0;

     450:

    +451:     def __spin_on_native_lock(self, thread_lock, timeout):

    static int __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore__Semaphore__spin_on_native_lock(struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_thread_lock, PyObject *__pyx_v_timeout) {PyObject *__pyx_v_expiration = NULL;int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_Semaphore__spin_on_native_lock", 0);/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_WriteUnraisable("gevent._gevent_c_semaphore.Semaphore._Semaphore__spin_on_native_lock", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);__pyx_r = 0;__pyx_L0:;__Pyx_XDECREF(__pyx_v_expiration);__Pyx_RefNannyFinishContext();return __pyx_r;}

    +452:         expiration = 0

    __Pyx_INCREF(__pyx_int_0);__pyx_v_expiration = __pyx_int_0;

    +453:         if timeout:

    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_timeout); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 453, __pyx_L1_error)if (__pyx_t_1) {}

    +454:             expiration = monotonic() + timeout

    __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);__pyx_t_3 = __pyx_v_6gevent_19_gevent_c_semaphore_monotonic; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 454, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF_SET(__pyx_v_expiration, __pyx_t_3);__pyx_t_3 = 0;

     455:

    +456:         self._drop_lock_for_switch_out()

    __pyx_t_3 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._drop_lock_for_switch_out(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 456, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    +457:         try:

    /*try:*/ {

     458:             # TODO: When timeout is given and the lock supports that

     459:             # (Python 3), pass that.

     460:             # Python 2 has terrible behaviour where lock acquires can't

     461:             # be interrupted, so we use a spin loop

    +462:             while not thread_lock.acquire(0):

    while (1) {__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_acquire); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 462, __pyx_L5_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_int_0};__pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 462, __pyx_L5_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 462, __pyx_L5_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_6 = (!__pyx_t_1);if (!__pyx_t_6) break;

    +463:                 if expiration and monotonic() >= expiration:

    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_expiration); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 463, __pyx_L5_error)if (__pyx_t_1) {} else {__pyx_t_6 = __pyx_t_1;goto __pyx_L10_bool_binop_done;}__Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);__pyx_t_2 = __pyx_v_6gevent_19_gevent_c_semaphore_monotonic; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 463, __pyx_L5_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_expiration, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 463, __pyx_L5_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 463, __pyx_L5_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_t_6 = __pyx_t_1;__pyx_L10_bool_binop_done:;if (__pyx_t_6) {}

    +464:                     return False

    __pyx_r = 0;goto __pyx_L4_return;

     465:

    +466:                 _native_sleep(0.001)

    __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore__native_sleep);__pyx_t_3 = __pyx_v_6gevent_19_gevent_c_semaphore__native_sleep; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_float_0_001};__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 466, __pyx_L5_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}

    +467:             return True

    __pyx_r = 1;goto __pyx_L4_return;}

     468:         finally:

    +469:             self._acquire_lock_for_switch_in()

    /*finally:*/ {__pyx_L5_error:;/*exception exit:*/{__Pyx_PyThreadState_declare__Pyx_PyThreadState_assign__pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);__Pyx_XGOTREF(__pyx_t_9);__Pyx_XGOTREF(__pyx_t_10);__Pyx_XGOTREF(__pyx_t_11);__Pyx_XGOTREF(__pyx_t_12);__Pyx_XGOTREF(__pyx_t_13);__Pyx_XGOTREF(__pyx_t_14);__pyx_t_5 = __pyx_lineno; __pyx_t_7 = __pyx_clineno; __pyx_t_8 = __pyx_filename;{__pyx_t_2 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._acquire_lock_for_switch_in(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 469, __pyx_L13_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_12);__Pyx_XGIVEREF(__pyx_t_13);__Pyx_XGIVEREF(__pyx_t_14);__Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);}__Pyx_XGIVEREF(__pyx_t_9);__Pyx_XGIVEREF(__pyx_t_10);__Pyx_XGIVEREF(__pyx_t_11);__Pyx_ErrRestore(__pyx_t_9, __pyx_t_10, __pyx_t_11);__pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;__pyx_lineno = __pyx_t_5; __pyx_clineno = __pyx_t_7; __pyx_filename = __pyx_t_8;goto __pyx_L1_error;__pyx_L13_error:;if (PY_MAJOR_VERSION >= 3) {__Pyx_XGIVEREF(__pyx_t_12);__Pyx_XGIVEREF(__pyx_t_13);__Pyx_XGIVEREF(__pyx_t_14);__Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);}__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;__Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;__pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;goto __pyx_L1_error;}__pyx_L4_return: {__pyx_t_6 = __pyx_r;__pyx_t_2 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._acquire_lock_for_switch_in(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self), 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 469, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_r = __pyx_t_6;goto __pyx_L0;}}

     470:

     471:

    +472: class BoundedSemaphore(Semaphore):

    struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_BoundedSemaphore {struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore __pyx_base;};static struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_BoundedSemaphore *__pyx_vtabptr_6gevent_19_gevent_c_semaphore_BoundedSemaphore;

     473:     """

     474:     BoundedSemaphore(value=1) -> BoundedSemaphore

     475:

     476:     A bounded semaphore checks to make sure its current value doesn't

     477:     exceed its initial value. If it does, :class:`ValueError` is

     478:     raised. In most situations semaphores are used to guard resources

     479:     with limited capacity. If the semaphore is released too many times

     480:     it's a sign of a bug.

     481:

     482:     If not given, *value* defaults to 1.

     483:     """

     484:

     485:     __slots__ = (

    +486:         '_initial_value',

    if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore->tp_dict, __pyx_n_s_slots, __pyx_tuple__26) < 0) __PYX_ERR(0, 485, __pyx_L1_error)PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);__pyx_tuple__26 = PyTuple_Pack(1, __pyx_n_s_initial_value); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 486, __pyx_L1_error)__Pyx_GOTREF(__pyx_tuple__26);__Pyx_GIVEREF(__pyx_tuple__26);

     487:     )

     488:

     489:     #: For monkey-patching, allow changing the class of error we raise

    +490:     _OVER_RELEASE_ERROR = ValueError

    if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore->tp_dict, __pyx_n_s_OVER_RELEASE_ERROR, __pyx_builtin_ValueError) < 0) __PYX_ERR(0, 490, __pyx_L1_error)PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);

     491:

    +492:     def __init__(self, *args, **kwargs):

    /* Python wrapper */static int __pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/static int __pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {PyObject *__pyx_v_args = 0;PyObject *__pyx_v_kwargs = 0;CYTHON_UNUSED const Py_ssize_t __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;if (unlikely(__pyx_kwds)) {__pyx_v_kwargs = __Pyx_KwargsAsDict_VARARGS(__pyx_kwds, __pyx_kwvalues);if (unlikely(!__pyx_v_kwargs)) return -1;__Pyx_GOTREF(__pyx_v_kwargs);} else {__pyx_v_kwargs = PyDict_New();if (unlikely(!__pyx_v_kwargs)) return -1;__Pyx_GOTREF(__pyx_v_kwargs);}__Pyx_INCREF(__pyx_args);__pyx_v_args = __pyx_args;__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_16BoundedSemaphore___init__(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);/* function exit code */__Pyx_DECREF(__pyx_v_args);__Pyx_DECREF(__pyx_v_kwargs);__Pyx_RefNannyFinishContext();return __pyx_r;}static int __pyx_pf_6gevent_19_gevent_c_semaphore_16BoundedSemaphore___init__(struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("__init__", 0);/* function exit code */__pyx_r = 0;goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_AddTraceback("gevent._gevent_c_semaphore.BoundedSemaphore.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = -1;__pyx_L0:;__Pyx_RefNannyFinishContext();return __pyx_r;}

    +493:         Semaphore.__init__(self, *args, **kwargs)

    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 493, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 493, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF((PyObject *)__pyx_v_self);__Pyx_GIVEREF((PyObject *)__pyx_v_self);PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));__pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 493, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_t_2 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 493, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 493, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    +494:         self._initial_value = self.counter

    __pyx_t_5 = __pyx_v_self->__pyx_base.counter;__pyx_v_self->_initial_value = __pyx_t_5;

     495:

    +496:     def release(self):

    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/static int __pyx_f_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_release(struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *__pyx_v_self, int __pyx_skip_dispatch) {int __pyx_v_counter;int __pyx_r;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("release", 0);/* Check if called by wrapper */if (unlikely(__pyx_skip_dispatch)) ;/* Check if overridden in Python */else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTSstatic PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));#endif__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_release); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 496, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);#ifdef __Pyx_CyFunction_USEDif (!__Pyx_IsCyOrPyCFunction(__pyx_t_1)#elseif (!PyCFunction_Check(__pyx_t_1)#endif        || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release)) {__Pyx_INCREF(__pyx_t_1);__pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);if (likely(__pyx_t_4)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);__Pyx_INCREF(__pyx_t_4);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_3, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_4, };__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 496, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;}__pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 496, __pyx_L1_error)__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_r = __pyx_t_5;__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;goto __pyx_L0;}#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS__pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));__pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {__pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;}#endif__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS}#endif}/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_XDECREF(__pyx_t_4);__Pyx_AddTraceback("gevent._gevent_c_semaphore.BoundedSemaphore.release", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = -1000;__pyx_L0:;__Pyx_RefNannyFinishContext();return __pyx_r;}/* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_2release, "BoundedSemaphore.release(self) -> int\n\n        Like :meth:`Semaphore.release`, but raises :class:`ValueError`\n        if the semaphore is being over-released.\n        ");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release = {"release", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_2release};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("release (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_2release(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *)__pyx_v_self));/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_2release(struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *__pyx_v_self) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("release", 0);__Pyx_XDECREF(__pyx_r);__pyx_t_1 = __pyx_f_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_release(__pyx_v_self, 1); if (unlikely(__pyx_t_1 == ((int)-1000))) __PYX_ERR(0, 496, __pyx_L1_error)__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 496, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_r = __pyx_t_2;__pyx_t_2 = 0;goto __pyx_L0;/* function exit code */__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_2);__Pyx_AddTraceback("gevent._gevent_c_semaphore.BoundedSemaphore.release", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BoundedSemaphore_release, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__27)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 496, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore->tp_dict, __pyx_n_s_release, __pyx_t_3) < 0) __PYX_ERR(0, 496, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);__pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_release, 496, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 496, __pyx_L1_error)

     497:         """

     498:         Like :meth:`Semaphore.release`, but raises :class:`ValueError`

     499:         if the semaphore is being over-released.

     500:         """

    +501:         if self.counter >= self._initial_value:

    __pyx_t_6 = (__pyx_v_self->__pyx_base.counter >= __pyx_v_self->_initial_value);if (unlikely(__pyx_t_6)) {}

    +502:             raise self._OVER_RELEASE_ERROR("Semaphore released too many times")

    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_OVER_RELEASE_ERROR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 502, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_3 = NULL;__pyx_t_5 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_5 = 1;}}{PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_kp_s_Semaphore_released_too_many_time};__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 502, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__Pyx_Raise(__pyx_t_1, 0, 0, 0);__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;__PYX_ERR(0, 502, __pyx_L1_error)

    +503:         counter = Semaphore.release(self)

    __pyx_t_5 = __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_release(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self), 1); if (unlikely(__pyx_t_5 == ((int)-1000))) __PYX_ERR(0, 503, __pyx_L1_error)__pyx_v_counter = __pyx_t_5;

     504:         # When we are absolutely certain that no one holds this semaphore,

     505:         # release our hub and go back to floating. This assists in cross-thread

     506:         # uses.

    +507:         if counter == self._initial_value:

    __pyx_t_6 = (__pyx_v_counter == __pyx_v_self->_initial_value);if (__pyx_t_6) {}

    +508:             self.hub = None # pylint:disable=attribute-defined-outside-init

    __Pyx_INCREF(Py_None);__Pyx_GIVEREF(Py_None);__Pyx_GOTREF((PyObject *)__pyx_v_self->__pyx_base.__pyx_base.hub);__Pyx_DECREF((PyObject *)__pyx_v_self->__pyx_base.__pyx_base.hub);__pyx_v_self->__pyx_base.__pyx_base.hub = ((struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *)Py_None);

    +509:         return counter

    __pyx_r = __pyx_v_counter;goto __pyx_L0;

     510:

    +511:     def _at_fork_reinit(self):

    /* Python wrapper */static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_5_at_fork_reinit(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_4_at_fork_reinit, "BoundedSemaphore._at_fork_reinit(self)");static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_5_at_fork_reinit = {"_at_fork_reinit", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_5_at_fork_reinit, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_4_at_fork_reinit};static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_5_at_fork_reinit(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {CYTHON_UNUSED PyObject *const *__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);PyObject *__pyx_r = 0;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_at_fork_reinit (wrapper)", 0);__pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_4_at_fork_reinit(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *)__pyx_v_self));/* function exit code */__Pyx_RefNannyFinishContext();return __pyx_r;}static PyObject *__pyx_pf_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_4_at_fork_reinit(struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *__pyx_v_self) {PyObject *__pyx_r = NULL;__Pyx_RefNannyDeclarations__Pyx_RefNannySetupContext("_at_fork_reinit", 0);/* function exit code */__pyx_r = Py_None; __Pyx_INCREF(Py_None);goto __pyx_L0;__pyx_L1_error:;__Pyx_XDECREF(__pyx_t_1);__Pyx_XDECREF(__pyx_t_2);__Pyx_XDECREF(__pyx_t_3);__Pyx_AddTraceback("gevent._gevent_c_semaphore.BoundedSemaphore._at_fork_reinit", __pyx_clineno, __pyx_lineno, __pyx_filename);__pyx_r = NULL;__pyx_L0:;__Pyx_XGIVEREF(__pyx_r);__Pyx_RefNannyFinishContext();return __pyx_r;}__pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_5_at_fork_reinit, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BoundedSemaphore__at_fork_reinit, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 511, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore->tp_dict, __pyx_n_s_at_fork_reinit, __pyx_t_3) < 0) __PYX_ERR(0, 511, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);

    +512:         super(BoundedSemaphore, self)._at_fork_reinit()

    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_INCREF((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);__Pyx_GIVEREF((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore));__Pyx_INCREF((PyObject *)__pyx_v_self);__Pyx_GIVEREF((PyObject *)__pyx_v_self);PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_self));__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 512, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_at_fork_reinit); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_3 = NULL;__pyx_t_4 = 0;if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {__pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);if (likely(__pyx_t_3)) {PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);__Pyx_INCREF(__pyx_t_3);__Pyx_INCREF(function);__Pyx_DECREF_SET(__pyx_t_2, function);__pyx_t_4 = 1;}}{PyObject *__pyx_callargs[1] = {__pyx_t_3, };__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 512, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_1);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;}__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +513:         self.counter = self._initial_value

    __pyx_t_4 = __pyx_v_self->_initial_value;__pyx_v_self->__pyx_base.counter = __pyx_t_4;

     514:

     515:

     516: # By building the semaphore with Cython under PyPy, we get

     517: # atomic operations (specifically, exiting/releasing), at the

     518: # cost of some speed (one trivial semaphore micro-benchmark put the pure-python version

     519: # at around 1s and the compiled version at around 4s). Some clever subclassing

     520: # and having only the bare minimum be in cython might help reduce that penalty.

     521: # NOTE: You must use version 0.23.4 or later to avoid a memory leak.

     522: # https://mail.python.org/pipermail/cython-devel/2015-October/004571.html

     523: # However, that's all for naught on up to and including PyPy 4.0.1 which

     524: # have some serious crashing bugs with GC interacting with cython.

     525: # It hasn't been tested since then, and PURE_PYTHON is assumed to be true

     526: # for PyPy in all cases anyway, so this does nothing.

     527:

    +528: from gevent._util import import_c_accel

    __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 528, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_INCREF(__pyx_n_s_import_c_accel);__Pyx_GIVEREF(__pyx_n_s_import_c_accel);PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_import_c_accel);__pyx_t_2 = __Pyx_Import(__pyx_n_s_gevent__util, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 528, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_import_c_accel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 528, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);if (PyDict_SetItem(__pyx_d, __pyx_n_s_import_c_accel, __pyx_t_3) < 0) __PYX_ERR(0, 528, __pyx_L1_error)__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +529: import_c_accel(globals(), 'gevent.__semaphore')

    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_import_c_accel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 529, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_2);__pyx_t_3 = __Pyx_Globals(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 529, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 529, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_4);__Pyx_GIVEREF(__pyx_t_3);PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);__Pyx_INCREF(__pyx_kp_s_gevent___semaphore);__Pyx_GIVEREF(__pyx_kp_s_gevent___semaphore);PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_kp_s_gevent___semaphore);__pyx_t_3 = 0;__pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 529, __pyx_L1_error)__Pyx_GOTREF(__pyx_t_3);__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;