@@ -1076,6 +1076,8 @@ rlock_acquire_restore(PyObject *op, PyObject *args)
10761076        return  NULL ;
10771077
10781078    _PyRecursiveMutex_Lock (& self -> lock );
1079+     self -> lock .thread  =  owner ;
1080+     self -> lock .level  =  count  -  1 ;
10791081    Py_RETURN_NONE ;
10801082}
10811083
@@ -1090,9 +1092,11 @@ rlock_release_save(PyObject *op, PyObject *Py_UNUSED(ignored))
10901092{
10911093    rlockobject  * self  =  (rlockobject * )op ;
10921094
1093-     PyThread_ident_t  owner  =  _Py_atomic_load_ullong_relaxed (& self -> lock .thread );
1094-     size_t  count  =  _Py_atomic_load_ulong_relaxed (& self -> lock .level );
1095-     if  (_PyRecursiveMutex_TryUnlock (& self -> lock ) <  0 ) {
1095+     PyThread_ident_t  owner  =  self -> lock .thread ;
1096+     size_t  count  =  self -> lock .level  +  1 ;
1097+ 
1098+     if  (_PyRecursiveMutex_TryUnlock (& self -> lock ) <  0 )
1099+     {
10961100        PyErr_SetString (PyExc_RuntimeError ,
10971101                        "cannot release un-acquired lock" );
10981102        return  NULL ;
@@ -1150,8 +1154,8 @@ static PyObject *
11501154rlock_repr (PyObject  * op )
11511155{
11521156    rlockobject  * self  =  (rlockobject * )op ;
1153-     PyThread_ident_t  owner  =  _Py_atomic_load_ullong_relaxed ( & self -> lock .thread ) ;
1154-     size_t  count  =  _Py_atomic_load_ulong_relaxed ( & self -> lock .level ) ;
1157+     PyThread_ident_t  owner  =  self -> lock .thread ;
1158+     size_t  count  =  self -> lock .level   +   1 ;
11551159    return  PyUnicode_FromFormat (
11561160        "<%s %s object owner=%"  PY_FORMAT_THREAD_IDENT_T  " count=%zu at %p>" ,
11571161        owner  ? "locked"  : "unlocked" ,
0 commit comments