mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
Issue #3001: Add a C implementation of recursive locks which is used by
default when instantiating a `Threading.RLock` object. This makes recursive locks as fast as regular non-recursive locks (previously, they were slower by 10x to 15x).
This commit is contained in:
parent
0e31201848
commit
434736a1a6
4 changed files with 296 additions and 5 deletions
|
@ -27,6 +27,10 @@ _start_new_thread = _thread.start_new_thread
|
|||
_allocate_lock = _thread.allocate_lock
|
||||
_get_ident = _thread.get_ident
|
||||
ThreadError = _thread.error
|
||||
try:
|
||||
_CRLock = _thread.RLock
|
||||
except AttributeError:
|
||||
_CRLock = None
|
||||
del _thread
|
||||
|
||||
|
||||
|
@ -79,8 +83,12 @@ def settrace(func):
|
|||
|
||||
Lock = _allocate_lock
|
||||
|
||||
def RLock(*args, **kwargs):
|
||||
return _RLock(*args, **kwargs)
|
||||
def RLock(verbose=None, *args, **kwargs):
|
||||
if verbose is None:
|
||||
verbose = _VERBOSE
|
||||
if (__debug__ and verbose) or _CRLock is None:
|
||||
return _PyRLock(verbose, *args, **kwargs)
|
||||
return _CRLock(*args, **kwargs)
|
||||
|
||||
class _RLock(_Verbose):
|
||||
|
||||
|
@ -156,6 +164,8 @@ class _RLock(_Verbose):
|
|||
def _is_owned(self):
|
||||
return self._owner == _get_ident()
|
||||
|
||||
_PyRLock = _RLock
|
||||
|
||||
|
||||
def Condition(*args, **kwargs):
|
||||
return _Condition(*args, **kwargs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue