Generated by Cython 3.1.2

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_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_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 = __Pyx_PyList_Pack(2, __pyx_mstate_global->__pyx_n_u_Semaphore, __pyx_mstate_global->__pyx_n_u_BoundedSemaphore); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_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 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_sleep); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_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_mstate_global->__pyx_n_u_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 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_monotonic); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_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_mstate_global->__pyx_n_u_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 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_InvalidThreadUseError); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_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_mstate_global->__pyx_n_u_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 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_LoopExit); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 21, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_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_mstate_global->__pyx_n_u_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 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_Timeout); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_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_mstate_global->__pyx_n_u_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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("_get_linkable (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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;
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __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_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_1_get_linkable, 0, __pyx_mstate_global->__pyx_n_u_get_linkable, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_get_linkable, __pyx_t_3) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

      __pyx_t_2 = NULL;
      __Pyx_INCREF(__pyx_builtin___import__);
      __pyx_t_3 = __pyx_builtin___import__;
      __pyx_t_4 = 1;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_gevent__abstract_linkable};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        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;

    +026:     return x._abstract_linkable.AbstractLinkable

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_x, __pyx_mstate_global->__pyx_n_u_abstract_linkable); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_AbstractLinkable); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L0;

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

      __pyx_t_2 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_get_linkable); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 27, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = 1;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 27, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      __pyx_t_4 = __Pyx_Globals(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 27, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely((PyDict_SetItem(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_AbstractLinkable, __pyx_t_3) < 0))) __PYX_ERR(0, 27, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    +028: del _get_linkable

      if (__Pyx_PyObject_DelAttrStr(__pyx_m, __pyx_mstate_global->__pyx_n_u_get_linkable) < 0) __PYX_ERR(0, 28, __pyx_L1_error)

     029:

    +030: from gevent._hub_local import get_hub_if_exists

      __pyx_t_3 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_get_hub_if_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_gevent__hub_local, __pyx_t_3, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 30, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_get_hub_if_exists); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_get_hub_if_exists, __pyx_t_3) < 0) __PYX_ERR(0, 30, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    +031: from gevent._hub_local import get_hub

      __pyx_t_4 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_get_hub); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 31, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_gevent__hub_local, __pyx_t_4, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_get_hub); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 31, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_get_hub_noargs, __pyx_t_4) < 0) __PYX_ERR(0, 31, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    +032: from gevent.hub import spawn_raw

      __pyx_t_3 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_spawn_raw); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_gevent_hub, __pyx_t_3, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_spawn_raw); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_3);
      __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_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

     033:

     034: class _LockReleaseLink(object):

     035:     __slots__ = (

    +036:         'lock',

      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore__LockReleaseLink, __pyx_mstate_global->__pyx_n_u_slots, __pyx_mstate_global->__pyx_tuple[1]) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
    /* … */
      __pyx_mstate_global->__pyx_tuple[1] = PyTuple_Pack(1, __pyx_mstate_global->__pyx_n_u_lock); if (unlikely(!__pyx_mstate_global->__pyx_tuple[1])) __PYX_ERR(0, 36, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[1]);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[1]);

     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 Py_ssize_t __pyx_nargs;
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
      #endif
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_lock,0};
      PyObject* values[1] = {0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_VARARGS(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 39, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  1:
            values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 39, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__init__", 0) < 0) __PYX_ERR(0, 39, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 1; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, i); __PYX_ERR(0, 39, __pyx_L3_error) }
          }
        } else if (unlikely(__pyx_nargs != 1)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 39, __pyx_L3_error)
        }
        __pyx_v_lock = values[0];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 39, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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 */
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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;
    /* … */
      /* 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 Py_ssize_t __pyx_nargs;
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__call__ (wrapper)", 0);
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_,0};
      PyObject* values[1] = {0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_VARARGS(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 42, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  1:
            values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 42, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__call__", 0) < 0) __PYX_ERR(0, 42, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 1; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, i); __PYX_ERR(0, 42, __pyx_L3_error) }
          }
        } else if (unlikely(__pyx_nargs != 1)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 42, __pyx_L3_error)
        }
        __pyx_v__ = values[0];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 42, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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 */
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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;
    /* … */
      /* 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_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_v_self->lock;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_3 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_release, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     044:

    +045: _UNSET = object()

      __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_builtin_object);
      __pyx_t_2 = __pyx_builtin_object;
      __pyx_t_5 = 1;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
        __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 45, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
      }
      __Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore__UNSET);
      __Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore__UNSET, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 0;

    +046: _MULTI = object()

      __pyx_t_2 = NULL;
      __Pyx_INCREF(__pyx_builtin_object);
      __pyx_t_3 = __pyx_builtin_object;
      __pyx_t_5 = 1;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 46, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
      }
      __Pyx_XGOTREF(__pyx_v_6gevent_19_gevent_c_semaphore__MULTI);
      __Pyx_DECREF_SET(__pyx_v_6gevent_19_gevent_c_semaphore__MULTI, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      __pyx_t_4 = 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:     .. versionchanged:: 24.2.1

     082:        Uses Python 3 native lock timeouts for cross-thread operations instead

     083:        of spinning.

     084:     """

     085:

     086:     __slots__ = (

    +087:         'counter',

      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_slots, __pyx_mstate_global->__pyx_tuple[2]) < 0) __PYX_ERR(0, 86, __pyx_L1_error)
    /* … */
      __pyx_mstate_global->__pyx_tuple[2] = PyTuple_Pack(2, __pyx_mstate_global->__pyx_n_u_counter_2, __pyx_mstate_global->__pyx_n_u_multithreaded); if (unlikely(!__pyx_mstate_global->__pyx_tuple[2])) __PYX_ERR(0, 87, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[2]);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[2]);

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

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

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

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

     092:         # to ``_MULTI``.

     093:         '_multithreaded',

     094:     )

     095:

    +096:     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 Py_ssize_t __pyx_nargs;
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
      #endif
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_value,&__pyx_mstate_global->__pyx_n_u_hub,0};
      PyObject* values[2] = {0,0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_VARARGS(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 96, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  2:
            values[1] = __Pyx_ArgRef_VARARGS(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 96, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 96, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__init__", 0) < 0) __PYX_ERR(0, 96, __pyx_L3_error)
          if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)__pyx_mstate_global->__pyx_int_1));
          if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)Py_None));
        } else {
          switch (__pyx_nargs) {
            case  2:
            values[1] = __Pyx_ArgRef_VARARGS(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 96, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 96, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)__pyx_mstate_global->__pyx_int_1));
          if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)Py_None));
        }
        __pyx_v_value = values[0];
        __pyx_v_hub = values[1];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 2, __pyx_nargs); __PYX_ERR(0, 96, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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 */
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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;
    /* … */
      /* 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_XDECREF(__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_8);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = -1;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +097:         self.counter = value

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

    +098:         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)) {
    /* … */
      }

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

        __pyx_t_4 = NULL;
        __Pyx_INCREF(__pyx_builtin_ValueError);
        __pyx_t_5 = __pyx_builtin_ValueError;
        __pyx_t_6 = 1;
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_semaphore_initial_value_must_be};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 99, __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, 99, __pyx_L1_error)

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

      __pyx_t_7 = NULL;
      __Pyx_INCREF(__pyx_builtin_super);
      __pyx_t_8 = __pyx_builtin_super;
      __pyx_t_6 = 1;
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_7, ((PyObject *)__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore), ((PyObject *)__pyx_v_self)};
        __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 100, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
      }
      __pyx_t_5 = __pyx_t_4;
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_6 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_hub};
        __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_init, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 100, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    +101:         self._notify_all = False

      __pyx_v_self->__pyx_base._notify_all = 0;

    +102:         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;

     103:

    +104:     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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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;
    /* … */
      /* 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;
    }

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

      __Pyx_XDECREF(__pyx_r);
    /* … */
      __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_6, 9, 1 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1) + 6 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3) + 9 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 8 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5) + 2, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5));
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __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_5); __pyx_t_5 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L0;

    +106:             self.__class__.__name__,

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_t_2), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +107:             id(self),

      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_Format(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_x); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +108:             self.counter,

      __pyx_t_2 = __Pyx_PyUnicode_From_int(__pyx_v_self->counter, 0, ' ', 'd'); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);

    +109:             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, 109, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_t_4), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 109, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6[0] = __pyx_mstate_global->__pyx_kp_u__2;
      __pyx_t_6[1] = __pyx_t_1;
      __pyx_t_6[2] = __pyx_mstate_global->__pyx_kp_u_at_0x;
      __pyx_t_6[3] = __pyx_t_3;
      __pyx_t_6[4] = __pyx_mstate_global->__pyx_kp_u_counter;
      __pyx_t_6[5] = __pyx_t_2;
      __pyx_t_6[6] = __pyx_mstate_global->__pyx_kp_u_links;
      __pyx_t_6[7] = __pyx_t_5;
      __pyx_t_6[8] = __pyx_mstate_global->__pyx_kp_u__3;

     110:         )

     111:

    +112:     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;
      /* Check if called by wrapper */
      if (unlikely(__pyx_skip_dispatch)) ;
      /* Check if overridden in Python */
      else if (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_locked); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 112, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked)) {
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 112, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 112, __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_AddTraceback("gevent._gevent_c_semaphore.Semaphore.locked", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __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\nReturn a boolean indicating whether the semaphore can be\nacquired (`False` if the semaphore *can* be acquired). Most\nuseful with binary semaphores (those with an initial value of 1).\n\n:rtype: bool");
    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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("locked (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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_XDECREF(__pyx_r);
      __pyx_t_1 = __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_locked(__pyx_v_self, 1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 112, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 112, __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.locked", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_5locked, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore_locked, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_locked, __pyx_t_4) < 0) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

     113:         """

     114:         Return a boolean indicating whether the semaphore can be

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

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

     117:

     118:         :rtype: bool

     119:         """

    +120:         return self.counter <= 0

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

     121:

    +122:     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;
      /* Check if called by wrapper */
      if (unlikely(__pyx_skip_dispatch)) ;
      /* Check if overridden in Python */
      else if (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_release); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 122, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release)) {
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 122, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __pyx_t_6 = __Pyx_PyLong_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 122, __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_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\nRelease the semaphore, notifying any waiters if needed. There\nis 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");
    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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("release (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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_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, 122, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 122, __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_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_7release, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore_release, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 122, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_release, __pyx_t_4) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

     123:         """

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

     125:         is no return value.

     126:

     127:         .. note::

     128:

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

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

     131:             created with.)

     132:

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

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

     135:             resources.

     136:

     137:         :rtype: None

     138:         """

    +139:         self.counter += 1

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

    +140:         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, 140, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +141:         return self.counter

      __pyx_r = __pyx_v_self->counter;
      goto __pyx_L0;

     142:

    +143:     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;
      /* Check if called by wrapper */
      if (unlikely(__pyx_skip_dispatch)) ;
      /* Check if overridden in Python */
      else if (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_ready); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready)) {
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 143, __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_AddTraceback("gevent._gevent_c_semaphore.Semaphore.ready", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __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\nReturn a boolean indicating whether the semaphore can be\nacquired (`True` if the semaphore can be acquired).\n\n:rtype: bool");
    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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("ready (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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_XDECREF(__pyx_r);
      __pyx_t_1 = __pyx_f_6gevent_19_gevent_c_semaphore_9Semaphore_ready(__pyx_v_self, 1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 143, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __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.ready", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_9ready, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore_ready, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[3])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 143, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_ready, __pyx_t_4) < 0) __PYX_ERR(0, 143, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

     144:         """

     145:         Return a boolean indicating whether the semaphore can be

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

     147:

     148:         :rtype: bool

     149:         """

    +150:         return self.counter > 0

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

     151:

    +152:     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;
      /* Check if called by wrapper */
      if (unlikely(__pyx_skip_dispatch)) ;
      /* Check if overridden in Python */
      else if (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_start_notify); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify)) {
            __Pyx_XDECREF(__pyx_r);
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("_start_notify (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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_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, 152, __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_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore__start_notify, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[4])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 152, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_start_notify, __pyx_t_4) < 0) __PYX_ERR(0, 152, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    +153:         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, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     154:

    +155:     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;
    /* … */
      /* 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;
    }

    +156:         if waited:

      if (__pyx_v_waited) {
    /* … */
      }

    +157:             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, 157, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_r = __pyx_t_1;
        __pyx_t_1 = 0;
        goto __pyx_L0;

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

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

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

    +161:         return True

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

     162:

    +163:     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;
      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 (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_wait); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait)) {
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_timeout};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __pyx_t_6 = __Pyx_PyLong_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 163, __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_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\nWait 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");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_13wait = {"wait", (PyCFunction)(void(*)(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_FASTCALL
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      #endif
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("wait (wrapper)", 0);
      #if !CYTHON_METH_FASTCALL
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      #endif
      __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_timeout,0};
      PyObject* values[1] = {0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 163, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 163, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "wait", 0) < 0) __PYX_ERR(0, 163, __pyx_L3_error)
          if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)Py_None));
        } else {
          switch (__pyx_nargs) {
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 163, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)Py_None));
        }
        __pyx_v_timeout = values[0];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("wait", 0, 0, 1, __pyx_nargs); __PYX_ERR(0, 163, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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 */
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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_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, 163, __pyx_L1_error)
      __pyx_t_3 = __Pyx_PyLong_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __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_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_13wait, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore_wait, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[5])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 163, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_mstate_global->__pyx_tuple[3]);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_wait, __pyx_t_4) < 0) __PYX_ERR(0, 163, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* … */
      __pyx_mstate_global->__pyx_tuple[3] = PyTuple_Pack(1, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_tuple[3])) __PYX_ERR(0, 163, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[3]);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[3]);

     164:         """

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

     166:         *timeout* elapses.

     167:

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

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

     170:

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

     172:            this method will block.

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

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

     175:             the semaphore.

     176:         :rtype: int

     177:         """

    +178:         if self.counter > 0:

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

    +179:             return self.counter

        __pyx_r = __pyx_v_self->counter;
        goto __pyx_L0;

     180:

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

      __pyx_t_8.__pyx_n = 1;
      __pyx_t_8.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_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 181, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +182:         return self.counter

      __pyx_r = __pyx_v_self->counter;
      goto __pyx_L0;

     183:

    +184:     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;
      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 (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_acquire); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 184, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire)) {
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_v_blocking); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 184, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_6 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_6 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_t_5, __pyx_v_timeout};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 184, __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_24);
      __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\nacquire(blocking=True, timeout=None) -> bool\n\nAcquire 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.)");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire = {"acquire", (PyCFunction)(void(*)(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_FASTCALL
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      #endif
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("acquire (wrapper)", 0);
      #if !CYTHON_METH_FASTCALL
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      #endif
      __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_blocking,&__pyx_mstate_global->__pyx_n_u_timeout,0};
      PyObject* values[2] = {0,0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 184, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  2:
            values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 184, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 184, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "acquire", 0) < 0) __PYX_ERR(0, 184, __pyx_L3_error)
          if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)Py_None));
        } else {
          switch (__pyx_nargs) {
            case  2:
            values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 184, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 184, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)Py_None));
        }
        if (values[0]) {
          __pyx_v_blocking = __Pyx_PyObject_IsTrue(values[0]); if (unlikely((__pyx_v_blocking == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 184, __pyx_L3_error)
        } else {
          __pyx_v_blocking = ((int)1);
        }
        __pyx_v_timeout = values[1];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("acquire", 0, 0, 2, __pyx_nargs); __PYX_ERR(0, 184, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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 */
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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_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, 184, __pyx_L1_error)
      __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __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_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore_acquire, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[6])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 184, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_mstate_global->__pyx_tuple[4]);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_acquire, __pyx_t_4) < 0) __PYX_ERR(0, 184, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* … */
      __pyx_mstate_global->__pyx_tuple[4] = PyTuple_Pack(2, Py_True, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_tuple[4])) __PYX_ERR(0, 184, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[4]);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[4]);

     185:         """

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

     187:

     188:         Acquire the semaphore.

     189:

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

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

     192:            set to false).

     193:

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

     195:            until the semaphore is acquired.

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

     197:            specifies the maximum amount of seconds

     198:            this method will block.

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

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

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

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

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

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

     205:         """

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

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

    +208:         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;
      }

    +209:             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, 209, __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;

    +210:         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, 210, __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, 210, __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, 210, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_7) {
    /* … */
      }
      __pyx_L3:;

    +211:             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;

     212:

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

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

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

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

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

    +218:         invalid_thread_use = None

      __Pyx_INCREF(Py_None);
      __pyx_v_invalid_thread_use = Py_None;

    +219:         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_L6_except_error:;
        __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:;
      }

    +220:             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, 220, __pyx_L4_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    +221:         except InvalidThreadUseError as e:

        __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_v_6gevent_19_gevent_c_semaphore_InvalidThreadUseError);
        if (__pyx_t_11) {
          __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, 221, __pyx_L6_except_error)
          __Pyx_XGOTREF(__pyx_t_2);
          __Pyx_XGOTREF(__pyx_t_1);
          __Pyx_XGOTREF(__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_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
               __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
              if ( unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
              __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_XGOTREF(__pyx_t_20);
              __pyx_t_11 = __pyx_lineno; __pyx_t_13 = __pyx_clineno; __pyx_t_14 = __pyx_filename;
              {
                __Pyx_DECREF(__pyx_v_e); __pyx_v_e = 0;
              }
              __Pyx_XGIVEREF(__pyx_t_18);
              __Pyx_XGIVEREF(__pyx_t_19);
              __Pyx_XGIVEREF(__pyx_t_20);
              __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20);
              __Pyx_XGIVEREF(__pyx_t_15);
              __Pyx_XGIVEREF(__pyx_t_16);
              __Pyx_XGIVEREF(__pyx_t_17);
              __Pyx_ErrRestore(__pyx_t_15, __pyx_t_16, __pyx_t_17);
              __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0;
              __pyx_lineno = __pyx_t_11; __pyx_clineno = __pyx_t_13; __pyx_filename = __pyx_t_14;
              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;

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

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

    +224:             invalid_thread_use = e.args

            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_mstate_global->__pyx_n_u_args); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 224, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF_SET(__pyx_v_invalid_thread_use, __pyx_t_5);
            __pyx_t_5 = 0;

    +225:             e = None

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

    +226:             if not self.counter and blocking:

            __pyx_t_12 = (!(__pyx_v_self->counter != 0));
            if (__pyx_t_12) {
            } else {
              __pyx_t_7 = __pyx_t_12;
              goto __pyx_L18_bool_binop_done;
            }
            __pyx_t_7 = __pyx_v_blocking;
            __pyx_L18_bool_binop_done:;
            if (__pyx_t_7) {
    /* … */
            }
          }

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

    +228:                 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, 228, __pyx_L15_error)
              __pyx_t_5 = ((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_5)) __PYX_ERR(0, 228, __pyx_L15_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 228, __pyx_L15_error)
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 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;

     229:

    +230:         if self.counter > 0:

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

    +231:             self.counter -= 1

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

    +232:             return True

        __pyx_r = 1;
        goto __pyx_L0;

     233:

    +234:         if not blocking:

      __pyx_t_7 = (!__pyx_v_blocking);
      if (__pyx_t_7) {
    /* … */
      }

    +235:             return False

        __pyx_r = 0;
        goto __pyx_L0;

     236:

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

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

    +238:             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, 238, __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;

     239:

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

      __pyx_t_12 = (((PyObject *)__pyx_v_self->__pyx_base.hub) == Py_None);
      if (__pyx_t_12) {
      } else {
        __pyx_t_7 = __pyx_t_12;
        goto __pyx_L30_bool_binop_done;
      }
      __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_invalid_thread_use); if (unlikely((__pyx_t_12 < 0))) __PYX_ERR(0, 240, __pyx_L1_error)
      __pyx_t_21 = (!__pyx_t_12);
      __pyx_t_7 = __pyx_t_21;
      __pyx_L30_bool_binop_done:;
      if (__pyx_t_7) {
    /* … */
      }

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

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

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

    +244:             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, 244, __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, 244, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_r = __pyx_t_7;
        goto __pyx_L0;

    +245:                 (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, 245, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, Py_None) != (0)) __PYX_ERR(0, 245, __pyx_L1_error);
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, Py_None) != (0)) __PYX_ERR(0, 245, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_4);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4) != (0)) __PYX_ERR(0, 245, __pyx_L1_error);
        __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_NoHubs);
        __Pyx_GIVEREF(__pyx_mstate_global->__pyx_n_u_NoHubs);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_mstate_global->__pyx_n_u_NoHubs) != (0)) __PYX_ERR(0, 245, __pyx_L1_error);
        __pyx_t_4 = 0;

     246:                 blocking,

     247:                 timeout

     248:             )

     249:

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

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

    +252:         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_L34_except_error:;
        __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:;
      }

    +253:             success = self._wait(timeout)

          __pyx_t_22.__pyx_n = 1;
          __pyx_t_22.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_22); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 253, __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, 253, __pyx_L32_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_v_success = __pyx_t_7;

    +254:         except LoopExit as ex:

        __pyx_t_13 = __Pyx_PyErr_ExceptionMatches(__pyx_v_6gevent_19_gevent_c_semaphore_LoopExit);
        if (__pyx_t_13) {
          __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, 254, __pyx_L34_except_error)
          __Pyx_XGOTREF(__pyx_t_4);
          __Pyx_XGOTREF(__pyx_t_1);
          __Pyx_XGOTREF(__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_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0;
              __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0;
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
               __Pyx_ExceptionSwap(&__pyx_t_17, &__pyx_t_16, &__pyx_t_15);
              if ( unlikely(__Pyx_GetException(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18) < 0)) __Pyx_ErrFetch(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18);
              __Pyx_XGOTREF(__pyx_t_20);
              __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_t_13 = __pyx_lineno; __pyx_t_11 = __pyx_clineno; __pyx_t_25 = __pyx_filename;
              {
                __Pyx_DECREF(__pyx_v_ex); __pyx_v_ex = 0;
              }
              __Pyx_XGIVEREF(__pyx_t_17);
              __Pyx_XGIVEREF(__pyx_t_16);
              __Pyx_XGIVEREF(__pyx_t_15);
              __Pyx_ExceptionReset(__pyx_t_17, __pyx_t_16, __pyx_t_15);
              __Pyx_XGIVEREF(__pyx_t_20);
              __Pyx_XGIVEREF(__pyx_t_19);
              __Pyx_XGIVEREF(__pyx_t_18);
              __Pyx_ErrRestore(__pyx_t_20, __pyx_t_19, __pyx_t_18);
              __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0;
              __pyx_lineno = __pyx_t_13; __pyx_clineno = __pyx_t_11; __pyx_filename = __pyx_t_25;
              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;

    +255:             args = ex.args

            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_ex, __pyx_mstate_global->__pyx_n_u_args); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 255, __pyx_L43_error)
            __Pyx_GOTREF(__pyx_t_5);
            if (!(likely(PyTuple_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_t_5))) __PYX_ERR(0, 255, __pyx_L43_error)
            __pyx_v_args = ((PyObject*)__pyx_t_5);
            __pyx_t_5 = 0;

    +256:             ex = None

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

    +257:             if self.counter:

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

    +258:                 success = True

              __pyx_v_success = 1;

     259:             else:

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

    +261:                 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, 261, __pyx_L43_error)
              }
              __pyx_t_23 = __Pyx_PyTuple_GET_SIZE(__pyx_v_args); if (unlikely(__pyx_t_23 == ((Py_ssize_t)-1))) __PYX_ERR(0, 261, __pyx_L43_error)
              __pyx_t_21 = (__pyx_t_23 == 3);
              if (__pyx_t_21) {
              } else {
                __pyx_t_7 = __pyx_t_21;
                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, 261, __pyx_L43_error)
              }
              __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v_args, 1, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 261, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_mstate_global->__pyx_n_u_main_hub); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 261, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_21 < 0))) __PYX_ERR(0, 261, __pyx_L43_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __pyx_t_7 = __pyx_t_21;
              __pyx_L47_bool_binop_done:;
              if (unlikely(__pyx_t_7)) {
    /* … */
              }

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

    +263:                     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, 263, __pyx_L43_error)

    +264:                 return self.__acquire_from_other_thread(

              __pyx_t_5 = ((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_24), __pyx_v_blocking, __pyx_v_timeout); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 264, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
              __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L43_error)
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 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:;
          }

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

              __pyx_t_3 = ((PyObject *)__pyx_f_6gevent_19_gevent_c_hub_local_get_hub_if_exists(0)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_3);
              __pyx_t_5 = ((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_5)) __PYX_ERR(0, 265, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_24 = PyTuple_New(4); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 265, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_24);
              __Pyx_INCREF((PyObject *)__pyx_v_self->__pyx_base.hub);
              __Pyx_GIVEREF((PyObject *)__pyx_v_self->__pyx_base.hub);
              if (__Pyx_PyTuple_SET_ITEM(__pyx_t_24, 0, ((PyObject *)__pyx_v_self->__pyx_base.hub)) != (0)) __PYX_ERR(0, 265, __pyx_L43_error);
              __Pyx_GIVEREF(__pyx_t_3);
              if (__Pyx_PyTuple_SET_ITEM(__pyx_t_24, 1, __pyx_t_3) != (0)) __PYX_ERR(0, 265, __pyx_L43_error);
              __Pyx_GIVEREF(__pyx_t_5);
              if (__Pyx_PyTuple_SET_ITEM(__pyx_t_24, 2, __pyx_t_5) != (0)) __PYX_ERR(0, 265, __pyx_L43_error);
              __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_LoopExit);
              __Pyx_GIVEREF(__pyx_mstate_global->__pyx_n_u_LoopExit);
              if (__Pyx_PyTuple_SET_ITEM(__pyx_t_24, 3, __pyx_mstate_global->__pyx_n_u_LoopExit) != (0)) __PYX_ERR(0, 265, __pyx_L43_error);
              __pyx_t_3 = 0;
              __pyx_t_5 = 0;

     266:                     blocking,

     267:                     timeout)

     268:

    +269:         if not success:

      __pyx_t_7 = (!__pyx_v_success);
      if (__pyx_t_7) {
    /* … */
      }

    +270:             assert timeout is not None

        #ifndef CYTHON_WITHOUT_ASSERTIONS
        if (unlikely(__pyx_assertions_enabled())) {
          __pyx_t_7 = (__pyx_v_timeout != Py_None);
          if (unlikely(!__pyx_t_7)) {
            __Pyx_Raise(__pyx_builtin_AssertionError, 0, 0, 0);
            __PYX_ERR(0, 270, __pyx_L1_error)
          }
        }
        #else
        if ((1)); else __PYX_ERR(0, 270, __pyx_L1_error)
        #endif

     271:             # Our timer expired.

    +272:             return False

        __pyx_r = 0;
        goto __pyx_L0;

     273:

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

     275:         # awoke. Therefore, the counter is ours

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

      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(__pyx_assertions_enabled())) {
        __pyx_t_7 = (__pyx_v_self->counter > 0);
        if (unlikely(!__pyx_t_7)) {
          __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_v_self->counter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 276, __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, 276, __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, 276, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 276, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_2);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2) != (0)) __PYX_ERR(0, 276, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_1);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1) != (0)) __PYX_ERR(0, 276, __pyx_L1_error);
          __Pyx_INCREF(__pyx_v_timeout);
          __Pyx_GIVEREF(__pyx_v_timeout);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_timeout) != (0)) __PYX_ERR(0, 276, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_4);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4) != (0)) __PYX_ERR(0, 276, __pyx_L1_error);
          __pyx_t_2 = 0;
          __pyx_t_1 = 0;
          __pyx_t_4 = 0;
          __pyx_t_4 = PyTuple_Pack(1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 276, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_4, 0, 0);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __PYX_ERR(0, 276, __pyx_L1_error)
        }
      }
      #else
      if ((1)); else __PYX_ERR(0, 276, __pyx_L1_error)
      #endif

    +277:         self.counter -= 1

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

    +278:         return True

      __pyx_r = 1;
      goto __pyx_L0;

     279:

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

      __Pyx_GetNameInClass(__pyx_t_4, (PyObject*)__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_acquire); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 280, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_py3k_acquire, __pyx_t_4) < 0) __PYX_ERR(0, 280, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

     281:

    +282:     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;
      /* Check if called by wrapper */
      if (unlikely(__pyx_skip_dispatch)) ;
      /* Check if overridden in Python */
      else if (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_enter); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__)) {
            __Pyx_XDECREF(__pyx_r);
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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_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, 282, __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_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore___enter, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[7])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 282, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_enter, __pyx_t_4) < 0) __PYX_ERR(0, 282, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    +283:         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, 283, __pyx_L1_error)

     284:

    +285:     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;
      /* Check if called by wrapper */
      if (unlikely(__pyx_skip_dispatch)) ;
      /* Check if overridden in Python */
      else if (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_exit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 285, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__)) {
            __Pyx_XDECREF(__pyx_r);
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[4] = {__pyx_t_3, __pyx_v_t, __pyx_v_v, __pyx_v_tb};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (4-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 285, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __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(*)(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_FASTCALL
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      #endif
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
      #if !CYTHON_METH_FASTCALL
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      #endif
      __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_t,&__pyx_mstate_global->__pyx_n_u_v,&__pyx_mstate_global->__pyx_n_u_tb,0};
      PyObject* values[3] = {0,0,0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 285, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  3:
            values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 285, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  2:
            values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 285, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 285, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__exit__", 0) < 0) __PYX_ERR(0, 285, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 3; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, i); __PYX_ERR(0, 285, __pyx_L3_error) }
          }
        } else if (unlikely(__pyx_nargs != 3)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 285, __pyx_L3_error)
          values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 285, __pyx_L3_error)
          values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 285, __pyx_L3_error)
        }
        __pyx_v_t = values[0];
        __pyx_v_v = values[1];
        __pyx_v_tb = values[2];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 285, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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 */
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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_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, 285, __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_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore___exit, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[8])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_exit, __pyx_t_4) < 0) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    +286:         self.release()

      __pyx_t_6 = ((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_6 == ((int)-1000))) __PYX_ERR(0, 286, __pyx_L1_error)

     287:

    +288:     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;
    /* … */
      /* 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;
    }

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

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

     291:         # other thread will eventually run notifications itself.

     292:         #

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

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

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

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

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

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

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

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

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

     302:         # acquired the lock.

     303:         #

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

     305:         # ``gevent.tests.test__semaphore``

     306:         # ``TestSemaphoreMultiThread.test_dueling_threads_with_hub``,

     307:         # but ONLY when running in PURE_PYTHON mode.

     308:         #

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

     310:         # running the callbacks?

    +311:         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, 311, __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, 311, __pyx_L1_error)

     312:

    +313:     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;
    /* … */
      /* 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;
    }

    +314:         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, 314, __pyx_L1_error)
      __pyx_t_2 = (!__pyx_t_1);
      if (__pyx_t_2) {
    /* … */
        goto __pyx_L3;
      }

    +315:             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, 315, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

     316:         else:

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

      /*else*/ {
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->__pyx_base._notifier, __pyx_mstate_global->__pyx_n_u_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 317, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 317, __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, 317, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __pyx_L3:;

     318:

    +319:     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;
    /* … */
      /* 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;
    }

    +320:         assert blocking

      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(__pyx_assertions_enabled())) {
        if (unlikely(!__pyx_v_blocking)) {
          __Pyx_Raise(__pyx_builtin_AssertionError, 0, 0, 0);
          __PYX_ERR(0, 320, __pyx_L1_error)
        }
      }
      #else
      if ((1)); else __PYX_ERR(0, 320, __pyx_L1_error)
      #endif

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

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

     323:         #

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

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

     326:         #

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

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

     329:         #

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

     331:         # solution. That involves using a lock.

     332:

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

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

    +335:         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, 335, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_ex_args, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 335, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop))))) __PYX_ERR(0, 335, __pyx_L1_error)
      __pyx_v_owning_hub = ((struct __pyx_obj_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop *)__pyx_t_1);
      __pyx_t_1 = 0;

    +336:         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, 336, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_ex_args, 1, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 336, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_mstate_global->__pyx_ptype_6gevent_29_gevent_c_greenlet_primitives_SwitchOutGreenletWithLoop))))) __PYX_ERR(0, 336, __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;

    +337:         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, 337, __pyx_L1_error)
      }
      __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v_ex_args, 2, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_current_greenlet = __pyx_t_1;
      __pyx_t_1 = 0;

     338:

    +339:         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) {
    /* … */
      }

    +340:             return self.__acquire_without_hubs(timeout)

        __Pyx_XDECREF(__pyx_r);
        __pyx_t_2 = ((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(PyErr_Occurred())) __PYX_ERR(0, 340, __pyx_L1_error)
        __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 340, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_r = __pyx_t_1;
        __pyx_t_1 = 0;
        goto __pyx_L0;

     341:

    +342:         if hub_for_this_thread is None:

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

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

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

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

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

     347:             # lock is the simplest way to go.

    +348:             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, 348, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_r = __pyx_t_1;
        __pyx_t_1 = 0;
        goto __pyx_L0;

     349:

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

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

    +352:         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, 352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

     353:                                              current_greenlet,

     354:                                              timeout)

     355:

    +356:     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;
    /* … */
      /* 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_4);
      __Pyx_XDECREF(__pyx_t_6);
      __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;
    }

     357:                                  hub_for_this_thread,

     358:                                  current_greenlet,

     359:                                  timeout):

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

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

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

     363:         # So...

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

      __pyx_t_2 = __pyx_v_hub_for_this_thread->loop;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_3 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_async, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __pyx_v_watcher = __pyx_t_1;
      __pyx_t_1 = 0;

    +365:         send = watcher.send_ignoring_arg

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_mstate_global->__pyx_n_u_send_ignoring_arg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_send = __pyx_t_1;
      __pyx_t_1 = 0;

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

      __pyx_t_2 = __pyx_v_watcher;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_current_greenlet, __pyx_mstate_global->__pyx_n_u_switch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 366, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = 0;
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_t_4, ((PyObject *)__pyx_v_self)};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_start, __pyx_callargs+__pyx_t_3, (3-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 366, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +367:         try:

      /*try:*/ {

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

        /*with:*/ {
          __pyx_t_4 = __pyx_v_6gevent_19_gevent_c_semaphore_Timeout;
          __Pyx_INCREF(__pyx_t_4);
          __pyx_t_3 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_timeout};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_start_new_or_dummy, __pyx_callargs+__pyx_t_3, (2-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 368, __pyx_L4_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __pyx_t_5 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_exit); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 368, __pyx_L4_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_2 = NULL;
          __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_enter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 368, __pyx_L6_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_3 = 1;
          #if CYTHON_UNPACK_METHODS
          if (likely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
            assert(__pyx_t_2);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_6, __pyx__function);
            __pyx_t_3 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
            __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 368, __pyx_L6_error)
            __Pyx_GOTREF(__pyx_t_4);
          }
          __pyx_t_6 = __pyx_t_4;
          __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          /*try:*/ {
            {
              /*try:*/ {
                __pyx_v_timer = __pyx_t_6;
                __pyx_t_6 = 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_4); __pyx_t_4 = 0;
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 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_4, &__pyx_t_6, &__pyx_t_1) < 0) __PYX_ERR(0, 368, __pyx_L12_except_error)
                __Pyx_XGOTREF(__pyx_t_4);
                __Pyx_XGOTREF(__pyx_t_6);
                __Pyx_XGOTREF(__pyx_t_1);
                __pyx_t_2 = PyTuple_Pack(3, __pyx_t_4, __pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 368, __pyx_L12_except_error)
                __Pyx_GOTREF(__pyx_t_2);
                __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
                if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 368, __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, 368, __pyx_L12_except_error)
                __pyx_t_24 = (!__pyx_t_13);
                if (unlikely(__pyx_t_24)) {
                  __Pyx_GIVEREF(__pyx_t_4);
                  __Pyx_GIVEREF(__pyx_t_6);
                  __Pyx_XGIVEREF(__pyx_t_1);
                  __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_6, __pyx_t_1);
                  __pyx_t_4 = 0;  __pyx_t_6 = 0;  __pyx_t_1 = 0;
                  __PYX_ERR(0, 368, __pyx_L12_except_error)
                }
                __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 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_5) {
                __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_mstate_global->__pyx_tuple[0], NULL);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 368, __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_5) {
                __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_mstate_global->__pyx_tuple[0], NULL);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 368, __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_5); __pyx_t_5 = 0;
          goto __pyx_L4_error;
          __pyx_L41:;
        }
      }
    /* … */
      __pyx_mstate_global->__pyx_tuple[0] = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_tuple[0])) __PYX_ERR(0, 368, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[0]);
      __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[0]);

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

     370:                 # state.

    +371:                 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_4); __pyx_t_4 = 0;
                  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    /* … */
                  __pyx_L18_except_error:;
                  __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:;
                }

    +372:                     while 1:

                    while (1) {

    +373:                         if self.counter > 0:

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

    +374:                             self.counter -= 1

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

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

                        #ifndef CYTHON_WITHOUT_ASSERTIONS
                        if (unlikely(__pyx_assertions_enabled())) {
                          __pyx_t_13 = (__pyx_v_self->counter >= 0);
                          if (unlikely(!__pyx_t_13)) {
                            __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 375, __pyx_L16_error)
                            __Pyx_GOTREF(__pyx_t_6);
                            __Pyx_INCREF((PyObject *)__pyx_v_self);
                            __Pyx_GIVEREF((PyObject *)__pyx_v_self);
                            if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self)) != (0)) __PYX_ERR(0, 375, __pyx_L16_error);
                            __pyx_t_1 = PyTuple_Pack(1, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 375, __pyx_L16_error)
                            __Pyx_GOTREF(__pyx_t_1);
                            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                            __Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_1, 0, 0);
                            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
                            __PYX_ERR(0, 375, __pyx_L16_error)
                          }
                        }
                        #else
                        if ((1)); else __PYX_ERR(0, 375, __pyx_L16_error)
                        #endif

    +376:                             return True

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

     377:

    +378:                         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, 378, __pyx_L16_error)
                      __Pyx_GOTREF(__pyx_t_1);
                      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     379:

     380:                         # Releases the object lock

    +381:                         self._switch_to_hub(hub_for_this_thread)

                      __pyx_t_14 = ((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_14 == ((int)-1))) __PYX_ERR(0, 381, __pyx_L16_error)

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

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

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

     385:                         # the timer expires

    +386:                         result = self.acquire(0)

                      __pyx_t_15.__pyx_n = 1;
                      __pyx_t_15.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_15); if (unlikely(__pyx_t_13 == ((int)-1000))) __PYX_ERR(0, 386, __pyx_L16_error)
                      __pyx_v_result = __pyx_t_13;

    +387:                         if result:

                      if (__pyx_v_result) {
    /* … */
                      }
                    }

    +388:                             return result

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

    +389:                 except Timeout as tex:

                  __pyx_t_14 = __Pyx_PyErr_ExceptionMatches(__pyx_v_6gevent_19_gevent_c_semaphore_Timeout);
                  if (__pyx_t_14) {
                    __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_6, &__pyx_t_4) < 0) __PYX_ERR(0, 389, __pyx_L18_except_error)
                    __Pyx_XGOTREF(__pyx_t_1);
                    __Pyx_XGOTREF(__pyx_t_6);
                    __Pyx_XGOTREF(__pyx_t_4);
                    __Pyx_INCREF(__pyx_t_6);
                    __pyx_v_tex = __pyx_t_6;
                    /*try:*/ {
    /* … */
                    /*finally:*/ {
                      __pyx_L31_error:;
                      /*exception exit:*/{
                        __Pyx_PyThreadState_declare
                        __Pyx_PyThreadState_assign
                        __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0;
                        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
                         __Pyx_ExceptionSwap(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23);
                        if ( unlikely(__Pyx_GetException(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20) < 0)) __Pyx_ErrFetch(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
                        __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_XGOTREF(__pyx_t_23);
                        __pyx_t_14 = __pyx_lineno; __pyx_t_16 = __pyx_clineno; __pyx_t_17 = __pyx_filename;
                        {
                          __Pyx_DECREF(__pyx_v_tex); __pyx_v_tex = 0;
                        }
                        __Pyx_XGIVEREF(__pyx_t_21);
                        __Pyx_XGIVEREF(__pyx_t_22);
                        __Pyx_XGIVEREF(__pyx_t_23);
                        __Pyx_ExceptionReset(__pyx_t_21, __pyx_t_22, __pyx_t_23);
                        __Pyx_XGIVEREF(__pyx_t_18);
                        __Pyx_XGIVEREF(__pyx_t_19);
                        __Pyx_XGIVEREF(__pyx_t_20);
                        __Pyx_ErrRestore(__pyx_t_18, __pyx_t_19, __pyx_t_20);
                        __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0;
                        __pyx_lineno = __pyx_t_14; __pyx_clineno = __pyx_t_16; __pyx_filename = __pyx_t_17;
                        goto __pyx_L18_except_error;
                      }
                      __pyx_L30_return: {
                        __pyx_t_23 = __pyx_r;
                        __pyx_r = 0;
                        __Pyx_DECREF(__pyx_v_tex); __pyx_v_tex = 0;
                        __pyx_r = __pyx_t_23;
                        __pyx_t_23 = 0;
                        goto __pyx_L19_except_return;
                      }
                    }
                  }
                  goto __pyx_L18_except_error;

    +390:                     if tex is not timer:

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

    +391:                         raise

                        __Pyx_GIVEREF(__pyx_t_1);
                        __Pyx_GIVEREF(__pyx_t_6);
                        __Pyx_XGIVEREF(__pyx_t_4);
                        __Pyx_ErrRestoreWithState(__pyx_t_1, __pyx_t_6, __pyx_t_4);
                        __pyx_t_1 = 0;  __pyx_t_6 = 0;  __pyx_t_4 = 0;
                        __PYX_ERR(0, 391, __pyx_L31_error)

    +392:                     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_4); __pyx_t_4 = 0;
                      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                      goto __pyx_L30_return;
                    }

     393:         finally:

    +394:             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); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L1_error)
    /* … */
            ((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); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L43_error)
    /* … */
          ((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); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L1_error)

    +395:             watcher.stop()

          __pyx_t_6 = __pyx_v_watcher;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_stop, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    /* … */
            __pyx_t_6 = __pyx_v_watcher;
            __Pyx_INCREF(__pyx_t_6);
            __pyx_t_3 = 0;
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
              __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_stop, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_1);
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    /* … */
          __pyx_t_6 = __pyx_v_watcher;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_stop, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +396:             watcher.close()

          __pyx_t_6 = __pyx_v_watcher;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_close, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __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_5 = 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_4); __pyx_t_4 = 0;
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
           __Pyx_ExceptionSwap(&__pyx_t_7, &__pyx_t_12, &__pyx_t_11);
          if ( unlikely(__Pyx_GetException(&__pyx_t_5, &__pyx_t_9, &__pyx_t_8) < 0)) __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_9, &__pyx_t_8);
          __Pyx_XGOTREF(__pyx_t_5);
          __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_16 = __pyx_lineno; __pyx_t_14 = __pyx_clineno; __pyx_t_25 = __pyx_filename;
          {
    /* … */
            __pyx_t_6 = __pyx_v_watcher;
            __Pyx_INCREF(__pyx_t_6);
            __pyx_t_3 = 0;
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
              __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_close, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_1);
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          }
          __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_5);
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_8);
          __Pyx_ErrRestore(__pyx_t_5, __pyx_t_9, __pyx_t_8);
          __pyx_t_5 = 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_16; __pyx_clineno = __pyx_t_14; __pyx_filename = __pyx_t_25;
          goto __pyx_L1_error;
          __pyx_L43_error:;
          __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_5); __pyx_t_5 = 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_6 = __pyx_v_watcher;
          __Pyx_INCREF(__pyx_t_6);
          __pyx_t_3 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_close, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_r = __pyx_t_11;
          __pyx_t_11 = 0;
          goto __pyx_L0;
        }
        __pyx_L5:;
      }

     397:

    +398:     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;
      /* Check if called by wrapper */
      if (unlikely(__pyx_skip_dispatch)) ;
      /* Check if overridden in Python */
      else if (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_Semaphore__acquire_from_other_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 398, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb)) {
            __Pyx_XDECREF(__pyx_r);
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = __Pyx_PyBool_FromLong(__pyx_v_blocking); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 398, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_6 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_6 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[5] = {__pyx_t_3, __pyx_v_results, __pyx_t_5, __pyx_v_timeout, __pyx_v_thread_lock};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_6, (5-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __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(*)(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_FASTCALL
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      #endif
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("_Semaphore__acquire_from_other_thread_cb (wrapper)", 0);
      #if !CYTHON_METH_FASTCALL
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      #endif
      __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
      {
        PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_results,&__pyx_mstate_global->__pyx_n_u_blocking,&__pyx_mstate_global->__pyx_n_u_timeout,&__pyx_mstate_global->__pyx_n_u_thread_lock,0};
      PyObject* values[4] = {0,0,0,0};
        const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
        if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 398, __pyx_L3_error)
        if (__pyx_kwds_len > 0) {
          switch (__pyx_nargs) {
            case  4:
            values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 398, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  3:
            values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 398, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  2:
            values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 398, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  1:
            values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
            if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 398, __pyx_L3_error)
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          const Py_ssize_t kwd_pos_args = __pyx_nargs;
          if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "_Semaphore__acquire_from_other_thread_cb", 0) < 0) __PYX_ERR(0, 398, __pyx_L3_error)
          for (Py_ssize_t i = __pyx_nargs; i < 4; i++) {
            if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, i); __PYX_ERR(0, 398, __pyx_L3_error) }
          }
        } else if (unlikely(__pyx_nargs != 4)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 398, __pyx_L3_error)
          values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 398, __pyx_L3_error)
          values[2] = __Pyx_ArgRef_FASTCALL(__pyx_args, 2);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[2])) __PYX_ERR(0, 398, __pyx_L3_error)
          values[3] = __Pyx_ArgRef_FASTCALL(__pyx_args, 3);
          if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[3])) __PYX_ERR(0, 398, __pyx_L3_error)
        }
        __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, 398, __pyx_L3_error)
        __pyx_v_timeout = values[2];
        __pyx_v_thread_lock = values[3];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, __pyx_nargs); __PYX_ERR(0, 398, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __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, 398, __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;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      goto __pyx_L7_cleaned_up;
      __pyx_L0:;
      for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
        Py_XDECREF(values[__pyx_temp]);
      }
      __pyx_L7_cleaned_up:;
      __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_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, 398, __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_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Semaphore__Semaphore__acquire_fr, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[9])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 398, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_mstate_global->__pyx_n_u_Semaphore__acquire_from_other_t, __pyx_t_4) < 0) __PYX_ERR(0, 398, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    +399:         try:

      /*try:*/ {

    +400:             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, 400, __pyx_L4_error)
        __pyx_v_result = __pyx_t_7;

    +401:             results.append(result)

        if (unlikely(__pyx_v_results == Py_None)) {
          PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append");
          __PYX_ERR(0, 401, __pyx_L4_error)
        }
        __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 401, __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, 401, __pyx_L4_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }

     402:         finally:

    +403:             thread_lock.release()

      /*finally:*/ {
        /*normal exit:*/{
          __pyx_t_2 = __pyx_v_thread_lock;
          __Pyx_INCREF(__pyx_t_2);
          __pyx_t_6 = 0;
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_release, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __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_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 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;
           __Pyx_ExceptionSwap(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
          if ( unlikely(__Pyx_GetException(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15) < 0)) __Pyx_ErrFetch(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
          __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_XGOTREF(__pyx_t_18);
          __pyx_t_10 = __pyx_lineno; __pyx_t_11 = __pyx_clineno; __pyx_t_12 = __pyx_filename;
          {
            __pyx_t_2 = __pyx_v_thread_lock;
            __Pyx_INCREF(__pyx_t_2);
            __pyx_t_6 = 0;
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
              __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_release, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __pyx_L7_error)
              __Pyx_GOTREF(__pyx_t_1);
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          }
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_17);
          __Pyx_XGIVEREF(__pyx_t_18);
          __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
          __Pyx_XGIVEREF(__pyx_t_13);
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_ErrRestore(__pyx_t_13, __pyx_t_14, __pyx_t_15);
          __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0;
          __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_11; __pyx_filename = __pyx_t_12;
          goto __pyx_L1_error;
          __pyx_L7_error:;
          __Pyx_XGIVEREF(__pyx_t_16);
          __Pyx_XGIVEREF(__pyx_t_17);
          __Pyx_XGIVEREF(__pyx_t_18);
          __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_17, __pyx_t_18);
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0;
          goto __pyx_L1_error;
        }
        __pyx_L5:;
      }

    +404:         return result

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

     405:

    +406:     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;
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_5);
      __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;
    }

    +407:         assert owning_hub is not get_hub_if_exists()

      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(__pyx_assertions_enabled())) {
        __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, 407, __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, 407, __pyx_L1_error)
        }
      }
      #else
      if ((1)); else __PYX_ERR(0, 407, __pyx_L1_error)
      #endif

    +408:         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, 408, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_thread_lock = __pyx_t_1;
      __pyx_t_1 = 0;

    +409:         thread_lock.acquire()

      __pyx_t_3 = __pyx_v_thread_lock;
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_4 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_acquire, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 409, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +410:         results = []

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

     411:

    +412:         owning_hub.loop.run_callback_threadsafe(

      __pyx_t_3 = __pyx_v_owning_hub->loop;
      __Pyx_INCREF(__pyx_t_3);

     413:             spawn_raw,

    +414:             self.__acquire_from_other_thread_cb,

      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_Semaphore__acquire_from_other_t); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 414, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);

     415:             results,

     416:             1,       # blocking,

     417:             timeout, # timeout,

    +418:             thread_lock)

      __pyx_t_4 = 0;
      {
        PyObject *__pyx_callargs[7] = {__pyx_t_3, __pyx_v_6gevent_19_gevent_c_semaphore_spawn_raw, __pyx_t_5, __pyx_v_results, __pyx_mstate_global->__pyx_int_1, __pyx_v_timeout, __pyx_v_thread_lock};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_run_callback_threadsafe, __pyx_callargs+__pyx_t_4, (7-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     419:

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

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

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

    +423:         self.__spin_on_native_lock(thread_lock, None)

      ((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); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 423, __pyx_L1_error)

    +424:         return results[0]

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

     425:

    +426:     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_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_5);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_without_hubs", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __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;
    }

    +427:         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, 427, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_thread_lock = __pyx_t_1;
      __pyx_t_1 = 0;

    +428:         thread_lock.acquire()

      __pyx_t_2 = __pyx_v_thread_lock;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_3 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_acquire, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 428, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +429:         absolute_expiration = 0

      __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
      __pyx_v_absolute_expiration = __pyx_mstate_global->__pyx_int_0;

    +430:         begin = 0

      __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
      __pyx_v_begin = __pyx_mstate_global->__pyx_int_0;

    +431:         if timeout:

      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_timeout); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 431, __pyx_L1_error)
      if (__pyx_t_4) {
    /* … */
      }

    +432:             absolute_expiration = monotonic() + timeout

        __pyx_t_2 = NULL;
        __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);
        __pyx_t_5 = __pyx_v_6gevent_19_gevent_c_semaphore_monotonic;
        __pyx_t_3 = 1;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
          assert(__pyx_t_2);
          PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(__pyx__function);
          __Pyx_DECREF_SET(__pyx_t_5, __pyx__function);
          __pyx_t_3 = 0;
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
          __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 432, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
        }
        __pyx_t_5 = PyNumber_Add(__pyx_t_1, __pyx_v_timeout); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 432, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF_SET(__pyx_v_absolute_expiration, __pyx_t_5);
        __pyx_t_5 = 0;

     433:

     434:         # Cython won't compile a lambda here

    +435:         link = _LockReleaseLink(thread_lock)

      __pyx_t_1 = NULL;
      __Pyx_INCREF((PyObject *)__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore__LockReleaseLink);
      __pyx_t_2 = ((PyObject *)__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore__LockReleaseLink);
      __pyx_t_3 = 1;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_thread_lock};
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_3, (2-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 435, __pyx_L1_error)
        __Pyx_GOTREF((PyObject *)__pyx_t_5);
      }
      __pyx_v_link = ((struct __pyx_obj_6gevent_19_gevent_c_semaphore__LockReleaseLink *)__pyx_t_5);
      __pyx_t_5 = 0;

    +436:         while 1:

      while (1) {

    +437:             self.__add_link(link)

        __pyx_t_5 = ((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_5)) __PYX_ERR(0, 437, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    +438:             if absolute_expiration:

        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_absolute_expiration); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 438, __pyx_L1_error)
        if (__pyx_t_4) {
    /* … */
        }

    +439:                 begin = monotonic()

          __pyx_t_2 = NULL;
          __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);
          __pyx_t_1 = __pyx_v_6gevent_19_gevent_c_semaphore_monotonic;
          __pyx_t_3 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
            assert(__pyx_t_2);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_2);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_1, __pyx__function);
            __pyx_t_3 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
            __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 439, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
          }
          __Pyx_DECREF_SET(__pyx_v_begin, __pyx_t_5);
          __pyx_t_5 = 0;

     440:

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

        __pyx_t_4 = ((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); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 441, __pyx_L1_error)
        __pyx_v_got_native = __pyx_t_4;

    +442:             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)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 442, __pyx_L1_error)

    +443:             if got_native:

        if (__pyx_v_got_native) {
    /* … */
        }

    +444:                 if self.acquire(0):

          __pyx_t_6.__pyx_n = 1;
          __pyx_t_6.blocking = 0;
          __pyx_t_4 = ((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_4 == ((int)-1000))) __PYX_ERR(0, 444, __pyx_L1_error)
          if (__pyx_t_4) {
    /* … */
          }

    +445:                     return True

            __pyx_r = 1;
            goto __pyx_L0;

    +446:             if absolute_expiration:

        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_absolute_expiration); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 446, __pyx_L1_error)
        if (__pyx_t_4) {
    /* … */
        }
      }

    +447:                 now = monotonic()

          __pyx_t_1 = NULL;
          __Pyx_INCREF(__pyx_v_6gevent_19_gevent_c_semaphore_monotonic);
          __pyx_t_2 = __pyx_v_6gevent_19_gevent_c_semaphore_monotonic;
          __pyx_t_3 = 1;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
            assert(__pyx_t_1);
            PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(__pyx__function);
            __Pyx_DECREF_SET(__pyx_t_2, __pyx__function);
            __pyx_t_3 = 0;
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL};
            __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_3, (1-__pyx_t_3) | (__pyx_t_3*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 447, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
          }
          __Pyx_XDECREF_SET(__pyx_v_now, __pyx_t_5);
          __pyx_t_5 = 0;

    +448:                 if now >= absolute_expiration:

          __pyx_t_5 = PyObject_RichCompare(__pyx_v_now, __pyx_v_absolute_expiration, Py_GE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 448, __pyx_L1_error)
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 448, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (__pyx_t_4) {
    /* … */
          }

    +449:                     return False

            __pyx_r = 0;
            goto __pyx_L0;

    +450:                 duration = now - begin

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

    +451:                 timeout -= duration

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

    +452:                 if timeout <= 0:

          __pyx_t_5 = PyObject_RichCompare(__pyx_v_timeout, __pyx_mstate_global->__pyx_int_0, Py_LE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 452, __pyx_L1_error)
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 452, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (__pyx_t_4) {
    /* … */
          }

    +453:                     return False

            __pyx_r = 0;
            goto __pyx_L0;

     454:

    +455:     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) {
      int __pyx_r;
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__spin_on_native_lock", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +456:         self._drop_lock_for_switch_out()

      __pyx_t_1 = ((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_1)) __PYX_ERR(0, 456, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +457:         try:

      /*try:*/ {

     458:             # Unlike Python 2, Python 3 thread locks

     459:             # can be interrupted when blocking, with or

     460:             # without a timeout. Python 2 didn't even

     461:             # support a timeout for non -blocking.

    +462:             if timeout:

        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_timeout); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 462, __pyx_L4_error)
        if (__pyx_t_2) {
    /* … */
        }

    +463:                 return thread_lock.acquire(True, timeout)

          __pyx_t_3 = __pyx_v_thread_lock;
          __Pyx_INCREF(__pyx_t_3);
          __pyx_t_4 = 0;
          {
            PyObject *__pyx_callargs[3] = {__pyx_t_3, Py_True, __pyx_v_timeout};
            __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_acquire, __pyx_callargs+__pyx_t_4, (3-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
            __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 463, __pyx_L4_error)
            __Pyx_GOTREF(__pyx_t_1);
          }
          __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 463, __pyx_L4_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_r = __pyx_t_2;
          goto __pyx_L3_return;

     464:

    +465:             return thread_lock.acquire()

        __pyx_t_3 = __pyx_v_thread_lock;
        __Pyx_INCREF(__pyx_t_3);
        __pyx_t_4 = 0;
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
          __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_acquire, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __pyx_L4_error)
          __Pyx_GOTREF(__pyx_t_1);
        }
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 465, __pyx_L4_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_r = __pyx_t_2;
        goto __pyx_L3_return;
      }

     466:         finally:

    +467:             self._acquire_lock_for_switch_in()

      /*finally:*/ {
        __pyx_L4_error:;
        /*exception exit:*/{
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
           __Pyx_ExceptionSwap(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
          if ( unlikely(__Pyx_GetException(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10) < 0)) __Pyx_ErrFetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          __Pyx_XGOTREF(__pyx_t_8);
          __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_t_5 = __pyx_lineno; __pyx_t_6 = __pyx_clineno; __pyx_t_7 = __pyx_filename;
          {
            __pyx_t_1 = ((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_1)) __PYX_ERR(0, 467, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          }
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_XGIVEREF(__pyx_t_12);
          __Pyx_XGIVEREF(__pyx_t_13);
          __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
          __Pyx_XGIVEREF(__pyx_t_8);
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_10);
          __Pyx_ErrRestore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0;
          __pyx_lineno = __pyx_t_5; __pyx_clineno = __pyx_t_6; __pyx_filename = __pyx_t_7;
          goto __pyx_L1_error;
          __pyx_L8_error:;
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_XGIVEREF(__pyx_t_12);
          __Pyx_XGIVEREF(__pyx_t_13);
          __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
          __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;
          __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0;
          goto __pyx_L1_error;
        }
        __pyx_L3_return: {
          __pyx_t_2 = __pyx_r;
          __pyx_t_1 = ((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_1)) __PYX_ERR(0, 467, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_r = __pyx_t_2;
          goto __pyx_L0;
        }
      }

     468:

     469:

    +470: 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;

     471:     """

     472:     BoundedSemaphore(value=1) -> BoundedSemaphore

     473:

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

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

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

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

     478:     it's a sign of a bug.

     479:

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

     481:     """

     482:

     483:     __slots__ = (

    +484:         '_initial_value',

      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore, __pyx_mstate_global->__pyx_n_u_slots, __pyx_mstate_global->__pyx_tuple[5]) < 0) __PYX_ERR(0, 483, __pyx_L1_error)

     485:     )

     486:

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

    +488:     _OVER_RELEASE_ERROR = ValueError

      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore, __pyx_mstate_global->__pyx_n_u_OVER_RELEASE_ERROR, __pyx_builtin_ValueError) < 0) __PYX_ERR(0, 488, __pyx_L1_error)

     489:

    +490:     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 Py_ssize_t __pyx_nargs;
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
      #if CYTHON_ASSUME_SAFE_SIZE
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
      #endif
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_VARARGS(__pyx_kwds) : 0;
      if (unlikely(__pyx_kwds_len < 0)) return -1;
      if (__pyx_kwds_len > 0) {
        if (unlikely(__Pyx_CheckKeywordStrings("__init__", __pyx_kwds) == -1)) return -1;
        __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;
    /* … */
      /* 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;
    }

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

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore), __pyx_mstate_global->__pyx_n_u_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 491, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 491, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF((PyObject *)__pyx_v_self);
      __Pyx_GIVEREF((PyObject *)__pyx_v_self);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self)) != (0)) __PYX_ERR(0, 491, __pyx_L1_error);
      __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 491, __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, 491, __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, 491, __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;

    +492:         self._initial_value = self.counter

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

     493:

    +494:     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;
      /* Check if called by wrapper */
      if (unlikely(__pyx_skip_dispatch)) ;
      /* Check if overridden in Python */
      else if (
      #if !CYTHON_USE_TYPE_SLOTS
      unlikely(Py_TYPE(((PyObject *)__pyx_v_self)) != __pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore &&
      __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), Py_TPFLAGS_HAVE_GC))
      #else
      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)))
      #endif
      ) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        static 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_mstate_global->__pyx_n_u_release); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 494, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          if (!__Pyx_IsSameCFunction(__pyx_t_1, (void(*)(void)) __pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release)) {
            __pyx_t_3 = NULL;
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1;
            __pyx_t_5 = 1;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
              assert(__pyx_t_3);
              PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx__function);
              __Pyx_DECREF_SET(__pyx_t_4, __pyx__function);
              __pyx_t_5 = 0;
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (1-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
              __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
            }
            __pyx_t_6 = __Pyx_PyLong_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 494, __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_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\nLike :meth:`Semaphore.release`, but raises :class:`ValueError`\nif the semaphore is being over-released.");
    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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("release (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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_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, 494, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyLong_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __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_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_BoundedSemaphore_release, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[10])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 494, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore, __pyx_mstate_global->__pyx_n_u_release, __pyx_t_4) < 0) __PYX_ERR(0, 494, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

     495:         """

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

     497:         if the semaphore is being over-released.

     498:         """

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

      __pyx_t_7 = (__pyx_v_self->__pyx_base.counter >= __pyx_v_self->_initial_value);
      if (unlikely(__pyx_t_7)) {
    /* … */
      }

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

        __pyx_t_2 = ((PyObject *)__pyx_v_self);
        __Pyx_INCREF(__pyx_t_2);
        __pyx_t_5 = 0;
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Semaphore_released_too_many_time};
          __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_OVER_RELEASE_ERROR, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 500, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
        }
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __PYX_ERR(0, 500, __pyx_L1_error)

    +501:         counter = Semaphore.release(self)

      __pyx_t_6 = __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_6 == ((int)-1000))) __PYX_ERR(0, 501, __pyx_L1_error)
      __pyx_v_counter = __pyx_t_6;

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

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

     504:         # uses.

    +505:         if counter == self._initial_value:

      __pyx_t_7 = (__pyx_v_counter == __pyx_v_self->_initial_value);
      if (__pyx_t_7) {
    /* … */
      }

    +506:             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);

    +507:         return counter

      __pyx_r = __pyx_v_counter;
      goto __pyx_L0;

     508:

    +509:     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;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("_at_fork_reinit (wrapper)", 0);
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __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;
    /* … */
      /* 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_XDECREF(__pyx_t_5);
      __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_4 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_5_at_fork_reinit, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_BoundedSemaphore__at_fork_reinit, NULL, __pyx_mstate_global->__pyx_n_u_gevent__gevent_c_semaphore, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[11])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 509, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore, __pyx_mstate_global->__pyx_n_u_at_fork_reinit, __pyx_t_4) < 0) __PYX_ERR(0, 509, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

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

      __pyx_t_4 = NULL;
      __Pyx_INCREF(__pyx_builtin_super);
      __pyx_t_5 = __pyx_builtin_super;
      __pyx_t_6 = 1;
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_4, ((PyObject *)__pyx_mstate_global->__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore), ((PyObject *)__pyx_v_self)};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 510, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      __pyx_t_2 = __pyx_t_3;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_6 = 0;
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_at_fork_reinit, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 510, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +511:         self.counter = self._initial_value

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

     512:

     513:

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

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

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

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

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

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

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

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

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

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

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

     525:

    +526: from gevent._util import import_c_accel

      __pyx_t_4 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_import_c_accel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_gevent__util, __pyx_t_4, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_import_c_accel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_import_c_accel, __pyx_t_4) < 0) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

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

      __pyx_t_4 = NULL;
      __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_import_c_accel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_Globals(); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 527, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = 1;
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_t_6, __pyx_mstate_global->__pyx_kp_u_gevent___semaphore};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_5, (3-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 527, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;