@@ -490,6 +490,18 @@ PyDoc_STRVAR(rlock_release_save_doc,
490490\n\
491491For internal use by `threading.Condition`." );
492492
493+ static PyObject *
494+ rlock_recursion_count (rlockobject * self , PyObject * Py_UNUSED (ignored ))
495+ {
496+ unsigned long tid = PyThread_get_thread_ident ();
497+ return PyLong_FromUnsignedLong (
498+ self -> rlock_owner == tid ? self -> rlock_count : 0UL );
499+ }
500+
501+ PyDoc_STRVAR (rlock_recursion_count_doc ,
502+ "_recursion_count() -> int\n\
503+ \n\
504+ For internal use by reentrancy checks." );
493505
494506static PyObject *
495507rlock_is_owned (rlockobject * self , PyObject * Py_UNUSED (ignored ))
@@ -565,6 +577,8 @@ static PyMethodDef rlock_methods[] = {
565577 METH_VARARGS , rlock_acquire_restore_doc },
566578 {"_release_save" , (PyCFunction )rlock_release_save ,
567579 METH_NOARGS , rlock_release_save_doc },
580+ {"_recursion_count" , (PyCFunction )rlock_recursion_count ,
581+ METH_NOARGS , rlock_recursion_count_doc },
568582 {"__enter__" , _PyCFunction_CAST (rlock_acquire ),
569583 METH_VARARGS | METH_KEYWORDS , rlock_acquire_doc },
570584 {"__exit__" , (PyCFunction )rlock_release ,
0 commit comments