Cython: _semaphore.py

Generated by Cython 3.0.11

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

Raw output: _semaphore.c

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

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

     002: ###

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

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

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

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

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

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

     009: ###

     010: from __future__ import print_function, absolute_import, division

     011:

    +012: __all__ = [

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

     013:     'Semaphore',

     014:     'BoundedSemaphore',

     015: ]

     016:

    +017: from time import sleep as _native_sleep

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

     018:

    +019: from gevent._compat import monotonic

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

    +020: from gevent.exceptions import InvalidThreadUseError

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

    +021: from gevent.exceptions import LoopExit

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

    +022: from gevent.timeout import Timeout

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

     023:

    +024: def _get_linkable():

    /* Python wrapper */
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_1_get_linkable(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
    PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore__get_linkable, "_get_linkable()");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_1_get_linkable = {"_get_linkable", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_1_get_linkable, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore__get_linkable};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_1_get_linkable(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      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_AddTraceback("gevent._gevent_c_semaphore._get_linkable", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_x);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__6 = PyTuple_Pack(1, __pyx_n_s_x); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 24, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__6);
      __Pyx_GIVEREF(__pyx_tuple__6);
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_1_get_linkable, 0, __pyx_n_s_get_linkable, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__7)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_linkable, __pyx_t_3) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_get_linkable, 24, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 24, __pyx_L1_error)

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

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

    +026:     return x._abstract_linkable.AbstractLinkable

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

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

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

    +028: del _get_linkable

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

     029:

    +030: from gevent._hub_local import get_hub_if_exists

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

    +031: from gevent._hub_local import get_hub

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

    +032: from gevent.hub import spawn_raw

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

     033:

     034: class _LockReleaseLink(object):

     035:     __slots__ = (

    +036:         'lock',

      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore__LockReleaseLink, __pyx_n_s_slots, __pyx_tuple__8) < 0) __PYX_ERR(0, 35, __pyx_L1_error)
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore__LockReleaseLink);
    /* … */
      __pyx_tuple__8 = PyTuple_Pack(1, __pyx_n_s_lock); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 36, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__8);
      __Pyx_GIVEREF(__pyx_tuple__8);

     037:     )

     038:

    +039:     def __init__(self, lock):

    /* Python wrapper */
    static int __pyx_pw_6gevent_19_gevent_c_semaphore_16_LockReleaseLink_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static int __pyx_pw_6gevent_19_gevent_c_semaphore_16_LockReleaseLink_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_lock = 0;
      CYTHON_UNUSED 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_MACROS
      __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 **__pyx_pyargnames[] = {&__pyx_n_s_lock,0};
      PyObject* values[1] = {0};
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_lock)) != 0)) {
              (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 39, __pyx_L3_error)
            else goto __pyx_L5_argtuple_error;
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 39, __pyx_L3_error)
          }
        } else if (unlikely(__pyx_nargs != 1)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        }
        __pyx_v_lock = values[0];
      }
      goto __pyx_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:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_VARARGS(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 */
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_VARARGS(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_MACROS
      __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 **__pyx_pyargnames[] = {&__pyx_n_s__2,0};
      PyObject* values[1] = {0};
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s__2)) != 0)) {
              (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 42, __pyx_L3_error)
            else goto __pyx_L5_argtuple_error;
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__call__") < 0)) __PYX_ERR(0, 42, __pyx_L3_error)
          }
        } else if (unlikely(__pyx_nargs != 1)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        }
        __pyx_v__ = values[0];
      }
      goto __pyx_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:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_VARARGS(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 */
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_VARARGS(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_XDECREF(__pyx_t_3);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore._LockReleaseLink.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +043:         self.lock.release()

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

     044:

    +045: _UNSET = object()

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

    +046: _MULTI = object()

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

     047:

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

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

     049:     """

     050:     Semaphore(value=1) -> Semaphore

     051:

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

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

     054:

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

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

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

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

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

     060:     called `acquire`.

     061:

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

     063:

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

     065:

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

     067:     on CPython, but does under PyPy.

     068:

     069:     .. versionchanged:: 1.4.0

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

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

     072:     .. versionchanged:: 1.5a3

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

     074:     .. versionchanged:: 1.5a3

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

     076:        unlinks waiters before calling them.

     077:     .. versionchanged:: 20.12.0

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

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

     080:

     081:     .. 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((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_slots, __pyx_tuple__9) < 0) __PYX_ERR(0, 86, __pyx_L1_error)
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
    /* … */
      __pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_counter, __pyx_n_s_multithreaded); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 87, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__9);
      __Pyx_GIVEREF(__pyx_tuple__9);

     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_MACROS
      __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 **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_hub,0};
      PyObject* values[2] = {0,0};
        values[0] = __Pyx_Arg_NewRef_VARARGS(((PyObject *)__pyx_int_1));
        values[1] = __Pyx_Arg_NewRef_VARARGS(((PyObject *)Py_None));
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (kw_args > 0) {
              PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_value);
              if (value) { values[0] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
              else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 96, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  1:
            if (kw_args > 0) {
              PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_hub);
              if (value) { values[1] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
              else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 96, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 96, __pyx_L3_error)
          }
        } else {
          switch (__pyx_nargs) {
            case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        __pyx_v_value = values[0];
        __pyx_v_hub = values[1];
      }
      goto __pyx_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:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_VARARGS(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 */
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_VARARGS(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_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_PyInt_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_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); 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)
    /* … */
      __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_semaphore_initial_value_must_be); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 99, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__3);
      __Pyx_GIVEREF(__pyx_tuple__3);

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

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

    +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_PyString_Format(__pyx_kp_s_s_at_0x_x_counter_s__links_s, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L0;

    +106:             self.__class__.__name__,

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    /* … */
      __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 106, __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)) __PYX_ERR(0, 106, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_1);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_3);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3)) __PYX_ERR(0, 106, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_4);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4)) __PYX_ERR(0, 106, __pyx_L1_error);
      __pyx_t_2 = 0;
      __pyx_t_1 = 0;
      __pyx_t_3 = 0;
      __pyx_t_4 = 0;

    +107:             id(self),

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

    +108:             self.counter,

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

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

     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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked)) {
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
            __pyx_t_5 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_5 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 112, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 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\n        Return a boolean indicating whether the semaphore can be\n        acquired (`False` if the semaphore *can* be acquired). Most\n        useful with binary semaphores (those with an initial value of 1).\n\n        :rtype: bool\n        ");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_5locked = {"locked", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_4locked};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_5locked(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      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_tuple__10 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__10);
      __Pyx_GIVEREF(__pyx_tuple__10);
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_5locked, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_locked, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_locked, __pyx_t_3) < 0) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
      __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_locked, 112, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 112, __pyx_L1_error)

     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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release)) {
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
            __pyx_t_5 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_5 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 122, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __pyx_t_6 = __Pyx_PyInt_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\n        Release the semaphore, notifying any waiters if needed. There\n        is no return value.\n\n        .. note::\n\n            This can be used to over-release the semaphore.\n            (Release more times than it has been acquired or was initially\n            created with.)\n\n            This is usually a sign of a bug, but under some circumstances it can be\n            used deliberately, for example, to model the arrival of additional\n            resources.\n\n        :rtype: None\n        ");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_7release = {"release", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_6release};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_7release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      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_PyInt_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_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_7release, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_release, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__12)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 122, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_release, __pyx_t_3) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
    /* … */
      __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_release, 122, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 122, __pyx_L1_error)

     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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready)) {
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
            __pyx_t_5 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_5 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 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\n        Return a boolean indicating whether the semaphore can be\n        acquired (`True` if the semaphore can be acquired).\n\n        :rtype: bool\n        ");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_9ready = {"ready", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_8ready};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_9ready(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      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_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_9ready, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_ready, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 143, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_ready, __pyx_t_3) < 0) __PYX_ERR(0, 143, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
    /* … */
      __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_ready, 143, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 143, __pyx_L1_error)

     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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify)) {
            __Pyx_XDECREF(__pyx_r);
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
            __pyx_t_5 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_5 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __pyx_r = __pyx_t_2;
            __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            goto __pyx_L0;
          }
          #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
          __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
          __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
          if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {
            __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
          }
          #endif
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        }
        #endif
      }
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._start_notify", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
    PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_10_start_notify, "Semaphore._start_notify(self)");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify = {"_start_notify", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_10_start_notify};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      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_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_11_start_notify, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore__start_notify, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 152, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_start_notify, __pyx_t_3) < 0) __PYX_ERR(0, 152, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
    /* … */
      __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_start_notify, 152, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 152, __pyx_L1_error)

    +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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait)) {
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
            __pyx_t_5 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_5 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_timeout};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __pyx_t_6 = __Pyx_PyInt_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\n        Wait until it is possible to acquire this semaphore, or until the optional\n        *timeout* elapses.\n\n        .. note:: If this semaphore was initialized with a *value* of 0,\n           this method will block forever if no timeout is given.\n\n        :keyword float timeout: If given, specifies the maximum amount of seconds\n           this method will block.\n        :return: A number indicating how many times the semaphore can be acquired\n            before blocking. *This could be 0,* if other waiters acquired\n            the semaphore.\n        :rtype: int\n        ");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_13wait = {"wait", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_12wait};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_13wait(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {
      PyObject *__pyx_v_timeout = 0;
      #if !CYTHON_METH_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_MACROS
      __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 **__pyx_pyargnames[] = {&__pyx_n_s_timeout,0};
      PyObject* values[1] = {0};
        values[0] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (kw_args > 0) {
              PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_timeout);
              if (value) { values[0] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
              else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 163, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "wait") < 0)) __PYX_ERR(0, 163, __pyx_L3_error)
          }
        } else {
          switch (__pyx_nargs) {
            case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        __pyx_v_timeout = values[0];
      }
      goto __pyx_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:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(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 */
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(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_PyInt_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_tuple__15 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_timeout); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 163, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__15);
      __Pyx_GIVEREF(__pyx_tuple__15);
      __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_wait, 163, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 163, __pyx_L1_error)
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_13wait, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_wait, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_tuple__17);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_wait, __pyx_t_3) < 0) __PYX_ERR(0, 163, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
      __pyx_tuple__17 = PyTuple_Pack(1, Py_None); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 163, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__17);
      __Pyx_GIVEREF(__pyx_tuple__17);

     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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire)) {
            __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_blocking); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL;
            __pyx_t_6 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
              if (likely(__pyx_t_5)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
                __Pyx_INCREF(__pyx_t_5);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_4, function);
                __pyx_t_6 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_t_3, __pyx_v_timeout};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 2+__pyx_t_6);
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 184, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            }
            __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 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\n        acquire(blocking=True, timeout=None) -> bool\n\n        Acquire the semaphore.\n\n        .. note:: If this semaphore was initialized with a *value* of 0,\n           this method will block forever (unless a timeout is given or blocking is\n           set to false).\n\n        :keyword bool blocking: If True (the default), this function will block\n           until the semaphore is acquired.\n        :keyword float timeout: If given, and *blocking* is true,\n           specifies the maximum amount of seconds\n           this method will block.\n        :return: A `bool` indicating whether the semaphore was acquired.\n           If ``blocking`` is True and ``timeout`` is None (the default), then\n           (so long as this semaphore was initialized with a size greater than 0)\n           this will always return True. If a timeout was given, and it expired before\n           the semaphore was acquired, False will be returned. (Note that this can still\n           raise a ``Timeout`` exception, if some other caller had already started a timer.)\n        ");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire = {"acquire", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_14acquire};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {
      int __pyx_v_blocking;
      PyObject *__pyx_v_timeout = 0;
      #if !CYTHON_METH_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_MACROS
      __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 **__pyx_pyargnames[] = {&__pyx_n_s_blocking,&__pyx_n_s_timeout,0};
      PyObject* values[2] = {0,0};
        values[1] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (kw_args > 0) {
              PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_blocking);
              if (value) { values[0] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
              else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 184, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  1:
            if (kw_args > 0) {
              PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_timeout);
              if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
              else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 184, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "acquire") < 0)) __PYX_ERR(0, 184, __pyx_L3_error)
          }
        } else {
          switch (__pyx_nargs) {
            case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        if (values[0]) {
          __pyx_v_blocking = __Pyx_PyObject_IsTrue(values[0]); if (unlikely((__pyx_v_blocking == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 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:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(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 */
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(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_tuple__18 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_blocking, __pyx_n_s_timeout); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 184, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__18);
      __Pyx_GIVEREF(__pyx_tuple__18);
      __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_acquire, 184, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 184, __pyx_L1_error)
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_15acquire, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_acquire, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__19)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_tuple__20);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_acquire, __pyx_t_3) < 0) __PYX_ERR(0, 184, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
      __pyx_tuple__20 = PyTuple_Pack(2, Py_True, Py_None); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 184, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__20);
      __Pyx_GIVEREF(__pyx_tuple__20);

     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;
              if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20);
              if ((PY_MAJOR_VERSION < 3) || 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;
              }
              if (PY_MAJOR_VERSION >= 3) {
                __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_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_e, __pyx_n_s_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 224, __pyx_L15_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF_SET(__pyx_v_invalid_thread_use, __pyx_t_3);
            __pyx_t_3 = 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_3 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__acquire_from_other_thread(__pyx_v_self, ((PyObject*)__pyx_v_invalid_thread_use), __pyx_v_blocking, __pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 228, __pyx_L15_error)
              __Pyx_GOTREF(__pyx_t_3);
              __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 228, __pyx_L15_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __pyx_r = __pyx_t_7;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              goto __pyx_L14_return;

     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)) __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)) __PYX_ERR(0, 245, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_4);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_4)) __PYX_ERR(0, 245, __pyx_L1_error);
        __Pyx_INCREF(__pyx_n_s_NoHubs);
        __Pyx_GIVEREF(__pyx_n_s_NoHubs);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_NoHubs)) __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;
              if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_17, &__pyx_t_16, &__pyx_t_15);
              if ((PY_MAJOR_VERSION < 3) || 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;
              }
              if (PY_MAJOR_VERSION >= 3) {
                __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_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_ex, __pyx_n_s_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 255, __pyx_L43_error)
            __Pyx_GOTREF(__pyx_t_3);
            if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_t_3))) __PYX_ERR(0, 255, __pyx_L43_error)
            __pyx_v_args = ((PyObject*)__pyx_t_3);
            __pyx_t_3 = 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_3 = __Pyx_GetItemInt_Tuple(__pyx_v_args, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 261, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_3);
              __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_main_hub); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 261, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __pyx_t_21 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_21 < 0))) __PYX_ERR(0, 261, __pyx_L43_error)
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 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_3 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->_Semaphore__acquire_from_other_thread(__pyx_v_self, ((PyObject*)__pyx_t_24), __pyx_v_blocking, __pyx_v_timeout); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 264, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
              __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L43_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __pyx_r = __pyx_t_7;
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              goto __pyx_L42_return;
            }
            __pyx_L45:;
          }

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

              __pyx_t_5 = ((PyObject *)__pyx_f_6gevent_19_gevent_c_hub_local_get_hub_if_exists(0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 265, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_3 = ((PyObject *)((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._getcurrent(((struct __pyx_obj_6gevent_27_gevent_c_abstract_linkable_AbstractLinkable *)__pyx_v_self))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 265, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_3);
              __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))) __PYX_ERR(0, 265, __pyx_L43_error);
              __Pyx_GIVEREF(__pyx_t_5);
              if (__Pyx_PyTuple_SET_ITEM(__pyx_t_24, 1, __pyx_t_5)) __PYX_ERR(0, 265, __pyx_L43_error);
              __Pyx_GIVEREF(__pyx_t_3);
              if (__Pyx_PyTuple_SET_ITEM(__pyx_t_24, 2, __pyx_t_3)) __PYX_ERR(0, 265, __pyx_L43_error);
              __Pyx_INCREF(__pyx_n_s_LoopExit);
              __Pyx_GIVEREF(__pyx_n_s_LoopExit);
              if (__Pyx_PyTuple_SET_ITEM(__pyx_t_24, 3, __pyx_n_s_LoopExit)) __PYX_ERR(0, 265, __pyx_L43_error);
              __pyx_t_5 = 0;
              __pyx_t_3 = 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_PyInt_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_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 276, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_2);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2)) __PYX_ERR(0, 276, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_1);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1)) __PYX_ERR(0, 276, __pyx_L1_error);
          __Pyx_INCREF(__pyx_v_timeout);
          __Pyx_GIVEREF(__pyx_v_timeout);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_timeout)) __PYX_ERR(0, 276, __pyx_L1_error);
          __Pyx_GIVEREF(__pyx_t_4);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_4)) __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_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 276, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_4, 0, 0);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __PYX_ERR(0, 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_3, (PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_acquire); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 280, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_py3k_acquire, __pyx_t_3) < 0) __PYX_ERR(0, 280, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);

     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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__)) {
            __Pyx_XDECREF(__pyx_r);
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
            __pyx_t_5 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_5 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __pyx_r = __pyx_t_2;
            __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            goto __pyx_L0;
          }
          #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
          __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
          __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
          if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {
            __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
          }
          #endif
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        }
        #endif
      }
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
    PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_16__enter__, "Semaphore.__enter__(self)");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__ = {"__enter__", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_16__enter__};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      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_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_17__enter__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore___enter, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__21)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 282, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_enter, __pyx_t_3) < 0) __PYX_ERR(0, 282, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
    /* … */
      __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_enter, 282, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 282, __pyx_L1_error)

    +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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__)) {
            __Pyx_XDECREF(__pyx_r);
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
            __pyx_t_5 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_5 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[4] = {__pyx_t_4, __pyx_v_t, __pyx_v_v, __pyx_v_tb};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 3+__pyx_t_5);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 285, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __pyx_r = __pyx_t_2;
            __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            goto __pyx_L0;
          }
          #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
          __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
          __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
          if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {
            __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
          }
          #endif
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        }
        #endif
      }
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/
    PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_18__exit__, "Semaphore.__exit__(self, t, v, tb)");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__ = {"__exit__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_18__exit__};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {
      PyObject *__pyx_v_t = 0;
      PyObject *__pyx_v_v = 0;
      PyObject *__pyx_v_tb = 0;
      #if !CYTHON_METH_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_MACROS
      __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 **__pyx_pyargnames[] = {&__pyx_n_s_t,&__pyx_n_s_v,&__pyx_n_s_tb,0};
      PyObject* values[3] = {0,0,0};
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_t)) != 0)) {
              (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 285, __pyx_L3_error)
            else goto __pyx_L5_argtuple_error;
            CYTHON_FALLTHROUGH;
            case  1:
            if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_v)) != 0)) {
              (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 285, __pyx_L3_error)
            else {
              __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 285, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tb)) != 0)) {
              (void)__Pyx_Arg_NewRef_FASTCALL(values[2]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 285, __pyx_L3_error)
            else {
              __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 285, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__exit__") < 0)) __PYX_ERR(0, 285, __pyx_L3_error)
          }
        } else if (unlikely(__pyx_nargs != 3)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
          values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
          values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        }
        __pyx_v_t = values[0];
        __pyx_v_v = values[1];
        __pyx_v_tb = values[2];
      }
      goto __pyx_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:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(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 */
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(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_tuple__22 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_t, __pyx_n_s_v, __pyx_n_s_tb); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__22);
      __Pyx_GIVEREF(__pyx_tuple__22);
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_19__exit__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore___exit, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_exit, __pyx_t_3) < 0) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
      __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(4, 0, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_exit, 285, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 285, __pyx_L1_error)

    +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_n_s_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_PyInt_From_long, 0, 0, 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_PyInt_From_long, 0, 0, 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_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_PyInt_From_long, 0, 0, 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_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_PyInt_From_long, 0, 0, 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_3);
      __Pyx_XDECREF(__pyx_t_5);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_using_two_hubs", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_watcher);
      __Pyx_XDECREF(__pyx_v_send);
      __Pyx_XDECREF(__pyx_v_timer);
      __Pyx_XDECREF(__pyx_v_tex);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

     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_PyObject_GetAttrStr(__pyx_v_hub_for_this_thread->loop, __pyx_n_s_async); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 364, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __pyx_v_watcher = __pyx_t_1;
      __pyx_t_1 = 0;

    +365:         send = watcher.send_ignoring_arg

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_send_ignoring_arg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 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_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_current_greenlet, __pyx_n_s_switch); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_t_3, ((PyObject *)__pyx_v_self)};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 2+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 366, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +367:         try:

      /*try:*/ {

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

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

     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_3); __pyx_t_3 = 0;
                  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 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_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 375, __pyx_L16_error)
                            __Pyx_GOTREF(__pyx_t_3);
                            __Pyx_INCREF((PyObject *)__pyx_v_self);
                            __Pyx_GIVEREF((PyObject *)__pyx_v_self);
                            if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 375, __pyx_L16_error);
                            __pyx_t_1 = PyTuple_Pack(1, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 375, __pyx_L16_error)
                            __Pyx_GOTREF(__pyx_t_1);
                            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
                            __Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_1, 0, 0);
                            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
                            __PYX_ERR(0, 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_3, &__pyx_t_2) < 0) __PYX_ERR(0, 389, __pyx_L18_except_error)
                    __Pyx_XGOTREF(__pyx_t_1);
                    __Pyx_XGOTREF(__pyx_t_3);
                    __Pyx_XGOTREF(__pyx_t_2);
                    __Pyx_INCREF(__pyx_t_3);
                    __pyx_v_tex = __pyx_t_3;
                    /*try:*/ {
    /* … */
                    /*finally:*/ {
                      __pyx_L31_error:;
                      /*exception exit:*/{
                        __Pyx_PyThreadState_declare
                        __Pyx_PyThreadState_assign
                        __pyx_t_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_5); __pyx_t_5 = 0;
                        if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23);
                        if ((PY_MAJOR_VERSION < 3) || 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;
                        }
                        if (PY_MAJOR_VERSION >= 3) {
                          __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_3);
                        __Pyx_XGIVEREF(__pyx_t_2);
                        __Pyx_ErrRestoreWithState(__pyx_t_1, __pyx_t_3, __pyx_t_2);
                        __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_2 = 0;
                        __PYX_ERR(0, 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_2); __pyx_t_2 = 0;
                      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 395, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_2 = NULL;
          __pyx_t_4 = 0;
          #if CYTHON_UNPACK_METHODS
          if (likely(PyMethod_Check(__pyx_t_3))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_3, function);
              __pyx_t_4 = 1;
            }
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    /* … */
            __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 395, __pyx_L43_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_2 = NULL;
            __pyx_t_4 = 0;
            #if CYTHON_UNPACK_METHODS
            if (likely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_2)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_2);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_4 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
              __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L43_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    /* … */
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_watcher, __pyx_n_s_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 395, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_2 = NULL;
          __pyx_t_4 = 0;
          #if CYTHON_UNPACK_METHODS
          if (likely(PyMethod_Check(__pyx_t_3))) {
            __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
            if (likely(__pyx_t_2)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_2);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_3, function);
              __pyx_t_4 = 1;
            }
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +396:             watcher.close()

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

     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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb)) {
            __Pyx_XDECREF(__pyx_r);
            __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_blocking); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL;
            __pyx_t_6 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_4))) {
              __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
              if (likely(__pyx_t_5)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
                __Pyx_INCREF(__pyx_t_5);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_4, function);
                __pyx_t_6 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[5] = {__pyx_t_5, __pyx_v_results, __pyx_t_3, __pyx_v_timeout, __pyx_v_thread_lock};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 4+__pyx_t_6);
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            }
            __pyx_r = __pyx_t_2;
            __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            goto __pyx_L0;
          }
          #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
          __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
          __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
          if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {
            __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
          }
          #endif
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
        }
        #endif
      }
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_5);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_from_other_thread_cb", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ); /*proto*/
    PyDoc_STRVAR(__pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_20_Semaphore__acquire_from_other_thread_cb, "Semaphore.__acquire_from_other_thread_cb(self, list results, bool blocking, timeout, thread_lock)");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb = {"_Semaphore__acquire_from_other_thread_cb", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_6gevent_19_gevent_c_semaphore_9Semaphore_20_Semaphore__acquire_from_other_thread_cb};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb(PyObject *__pyx_v_self,
    #if CYTHON_METH_FASTCALL
    PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
    #else
    PyObject *__pyx_args, PyObject *__pyx_kwds
    #endif
    ) {
      PyObject *__pyx_v_results = 0;
      int __pyx_v_blocking;
      PyObject *__pyx_v_timeout = 0;
      PyObject *__pyx_v_thread_lock = 0;
      #if !CYTHON_METH_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_MACROS
      __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 **__pyx_pyargnames[] = {&__pyx_n_s_results,&__pyx_n_s_blocking,&__pyx_n_s_timeout,&__pyx_n_s_thread_lock,0};
      PyObject* values[4] = {0,0,0,0};
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
            CYTHON_FALLTHROUGH;
            case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_results)) != 0)) {
              (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 398, __pyx_L3_error)
            else goto __pyx_L5_argtuple_error;
            CYTHON_FALLTHROUGH;
            case  1:
            if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_blocking)) != 0)) {
              (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 398, __pyx_L3_error)
            else {
              __Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, 1); __PYX_ERR(0, 398, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_timeout)) != 0)) {
              (void)__Pyx_Arg_NewRef_FASTCALL(values[2]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 398, __pyx_L3_error)
            else {
              __Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, 2); __PYX_ERR(0, 398, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  3:
            if (likely((values[3] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_thread_lock)) != 0)) {
              (void)__Pyx_Arg_NewRef_FASTCALL(values[3]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 398, __pyx_L3_error)
            else {
              __Pyx_RaiseArgtupleInvalid("_Semaphore__acquire_from_other_thread_cb", 1, 4, 4, 3); __PYX_ERR(0, 398, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "_Semaphore__acquire_from_other_thread_cb") < 0)) __PYX_ERR(0, 398, __pyx_L3_error)
          }
        } else if (unlikely(__pyx_nargs != 4)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
          values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
          values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
          values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        }
        __pyx_v_results = ((PyObject*)values[0]);
        __pyx_v_blocking = __Pyx_PyObject_IsTrue(values[1]); if (unlikely((__pyx_v_blocking == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 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:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(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;
      __pyx_L0:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
        }
      }
      __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_tuple__24 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_results, __pyx_n_s_blocking, __pyx_n_s_timeout, __pyx_n_s_thread_lock); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 398, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__24);
      __Pyx_GIVEREF(__pyx_tuple__24);
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_9Semaphore_21_Semaphore__acquire_from_other_thread_cb, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore__Semaphore__acquire_fr, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__25)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 398, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore, __pyx_n_s_Semaphore__acquire_from_other_t, __pyx_t_3) < 0) __PYX_ERR(0, 398, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_Semaphore);
      __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(5, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_Semaphore__acquire_from_other_t, 398, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 398, __pyx_L1_error)

    +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_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_release); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 403, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_4 = NULL;
          __pyx_t_6 = 0;
          #if CYTHON_UNPACK_METHODS
          if (likely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
              __pyx_t_6 = 1;
            }
          }
          #endif
          {
            PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
            __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          goto __pyx_L5;
        }
        __pyx_L4_error:;
        /*exception exit:*/{
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __pyx_t_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;
          if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18);
          if ((PY_MAJOR_VERSION < 3) || 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_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_release); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 403, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_4 = NULL;
            __pyx_t_6 = 0;
            #if CYTHON_UNPACK_METHODS
            if (likely(PyMethod_Check(__pyx_t_2))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_2, function);
                __pyx_t_6 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
              __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __pyx_L7_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            }
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          }
          if (PY_MAJOR_VERSION >= 3) {
            __Pyx_XGIVEREF(__pyx_t_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:;
          if (PY_MAJOR_VERSION >= 3) {
            __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_4);
      __Pyx_XDECREF(__pyx_t_6);
      __Pyx_AddTraceback("gevent._gevent_c_semaphore.Semaphore._Semaphore__acquire_using_other_hub", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_thread_lock);
      __Pyx_XDECREF(__pyx_v_results);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +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_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_acquire); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 409, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = NULL;
      __pyx_t_5 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_5 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 409, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +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_PyObject_GetAttrStr(__pyx_v_owning_hub->loop, __pyx_n_s_run_callback_threadsafe); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 412, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);

     413:             spawn_raw,

    +414:             self.__acquire_from_other_thread_cb,

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

     415:             results,

     416:             1,       # blocking,

     417:             timeout, # timeout,

    +418:             thread_lock)

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

     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_PyInt_From_long, 1, 0, 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_3);
      __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_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_acquire); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 428, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 428, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +429:         absolute_expiration = 0

      __Pyx_INCREF(__pyx_int_0);
      __pyx_v_absolute_expiration = __pyx_int_0;

    +430:         begin = 0

      __Pyx_INCREF(__pyx_int_0);
      __pyx_v_begin = __pyx_int_0;

    +431:         if timeout:

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

    +432:             absolute_expiration = monotonic() + timeout

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

     433:

     434:         # Cython won't compile a lambda here

    +435:         link = _LockReleaseLink(thread_lock)

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

    +436:         while 1:

      while (1) {

    +437:             self.__add_link(link)

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

    +438:             if absolute_expiration:

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

    +439:                 begin = monotonic()

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

     440:

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

        __pyx_t_5 = ((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_5;

    +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_5 = ((struct __pyx_vtabstruct_6gevent_19_gevent_c_semaphore_Semaphore *)__pyx_v_self->__pyx_base.__pyx_vtab)->acquire(__pyx_v_self, 0, &__pyx_t_6); if (unlikely(__pyx_t_5 == ((int)-1000))) __PYX_ERR(0, 444, __pyx_L1_error)
          if (__pyx_t_5) {
    /* … */
          }

    +445:                     return True

            __pyx_r = 1;
            goto __pyx_L0;

    +446:             if absolute_expiration:

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

    +447:                 now = monotonic()

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

    +448:                 if now >= absolute_expiration:

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

    +449:                     return False

            __pyx_r = 0;
            goto __pyx_L0;

    +450:                 duration = now - begin

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

    +451:                 timeout -= duration

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

    +452:                 if timeout <= 0:

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

    +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_XDECREF(__pyx_t_4);
      __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_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_acquire); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 463, __pyx_L4_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_4 = NULL;
          __pyx_t_5 = 0;
          #if CYTHON_UNPACK_METHODS
          if (likely(PyMethod_Check(__pyx_t_3))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_3, function);
              __pyx_t_5 = 1;
            }
          }
          #endif
          {
            PyObject *__pyx_callargs[3] = {__pyx_t_4, Py_True, __pyx_v_timeout};
            __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 2+__pyx_t_5);
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 463, __pyx_L4_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          }
          __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_PyObject_GetAttrStr(__pyx_v_thread_lock, __pyx_n_s_acquire); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 465, __pyx_L4_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = NULL;
        __pyx_t_5 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_5 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
          __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __pyx_L4_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        }
        __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_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
          if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
          __Pyx_XGOTREF(__pyx_t_9);
          __Pyx_XGOTREF(__pyx_t_10);
          __Pyx_XGOTREF(__pyx_t_11);
          __Pyx_XGOTREF(__pyx_t_12);
          __Pyx_XGOTREF(__pyx_t_13);
          __Pyx_XGOTREF(__pyx_t_14);
          __pyx_t_6 = __pyx_lineno; __pyx_t_7 = __pyx_clineno; __pyx_t_8 = __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;
          }
          if (PY_MAJOR_VERSION >= 3) {
            __Pyx_XGIVEREF(__pyx_t_12);
            __Pyx_XGIVEREF(__pyx_t_13);
            __Pyx_XGIVEREF(__pyx_t_14);
            __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
          }
          __Pyx_XGIVEREF(__pyx_t_9);
          __Pyx_XGIVEREF(__pyx_t_10);
          __Pyx_XGIVEREF(__pyx_t_11);
          __Pyx_ErrRestore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
          __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;
          __pyx_lineno = __pyx_t_6; __pyx_clineno = __pyx_t_7; __pyx_filename = __pyx_t_8;
          goto __pyx_L1_error;
          __pyx_L8_error:;
          if (PY_MAJOR_VERSION >= 3) {
            __Pyx_XGIVEREF(__pyx_t_12);
            __Pyx_XGIVEREF(__pyx_t_13);
            __Pyx_XGIVEREF(__pyx_t_14);
            __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
          }
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0;
          goto __pyx_L1_error;
        }
        __pyx_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((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore, __pyx_n_s_slots, __pyx_tuple__26) < 0) __PYX_ERR(0, 483, __pyx_L1_error)
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);
    /* … */
      __pyx_tuple__26 = PyTuple_Pack(1, __pyx_n_s_initial_value); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 484, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__26);
      __Pyx_GIVEREF(__pyx_tuple__26);

     485:     )

     486:

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

    +488:     _OVER_RELEASE_ERROR = ValueError

      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore, __pyx_n_s_OVER_RELEASE_ERROR, __pyx_builtin_ValueError) < 0) __PYX_ERR(0, 488, __pyx_L1_error)
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);

     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_MACROS
      __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);
      if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
      if (unlikely(__pyx_kwds)) {
        __pyx_v_kwargs = __Pyx_KwargsAsDict_VARARGS(__pyx_kwds, __pyx_kwvalues);
        if (unlikely(!__pyx_v_kwargs)) return -1;
        __Pyx_GOTREF(__pyx_v_kwargs);
      } else {
        __pyx_v_kwargs = PyDict_New();
        if (unlikely(!__pyx_v_kwargs)) return -1;
        __Pyx_GOTREF(__pyx_v_kwargs);
      }
      __Pyx_INCREF(__pyx_args);
      __pyx_v_args = __pyx_args;
      __pyx_r = __pyx_pf_6gevent_19_gevent_c_semaphore_16BoundedSemaphore___init__(((struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

      /* function exit code */
      __Pyx_DECREF(__pyx_v_args);
      __Pyx_DECREF(__pyx_v_kwargs);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static int __pyx_pf_6gevent_19_gevent_c_semaphore_16BoundedSemaphore___init__(struct __pyx_obj_6gevent_19_gevent_c_semaphore_BoundedSemaphore *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
      int __pyx_r;
    /* … */
      /* 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_ptype_6gevent_19_gevent_c_semaphore_Semaphore), __pyx_n_s_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))) __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 (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
        #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_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_n_s_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*) __pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release)) {
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
            __pyx_t_5 = 0;
            #if CYTHON_UNPACK_METHODS
            if (unlikely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_5 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
              __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __pyx_t_6 = __Pyx_PyInt_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\n        Like :meth:`Semaphore.release`, but raises :class:`ValueError`\n        if the semaphore is being over-released.\n        ");
    static PyMethodDef __pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release = {"release", (PyCFunction)__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release, METH_NOARGS, __pyx_doc_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_2release};
    static PyObject *__pyx_pw_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      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_PyInt_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_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_3release, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BoundedSemaphore_release, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__27)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 494, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore, __pyx_n_s_release, __pyx_t_3) < 0) __PYX_ERR(0, 494, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);
    /* … */
      __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_gevent__semaphore_py, __pyx_n_s_release, 494, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 494, __pyx_L1_error)

     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 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_OVER_RELEASE_ERROR); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = NULL;
        __pyx_t_5 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_5 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_kp_s_Semaphore_released_too_many_time};
          __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 500, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __PYX_ERR(0, 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_AddTraceback("gevent._gevent_c_semaphore.BoundedSemaphore._at_fork_reinit", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_6gevent_19_gevent_c_semaphore_16BoundedSemaphore_5_at_fork_reinit, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BoundedSemaphore__at_fork_reinit, NULL, __pyx_n_s_gevent__gevent_c_semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore, __pyx_n_s_at_fork_reinit, __pyx_t_3) < 0) __PYX_ERR(0, 509, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      PyType_Modified(__pyx_ptype_6gevent_19_gevent_c_semaphore_BoundedSemaphore);

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

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

    +511:         self.counter = self._initial_value

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

     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_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_n_s_import_c_accel);
      __Pyx_GIVEREF(__pyx_n_s_import_c_accel);
      if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_import_c_accel)) __PYX_ERR(0, 526, __pyx_L1_error);
      __pyx_t_2 = __Pyx_Import(__pyx_n_s_gevent__util, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_import_c_accel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_import_c_accel, __pyx_t_3) < 0) __PYX_ERR(0, 526, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

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

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