Commit 4fcd6f8f authored by Jason Madden's avatar Jason Madden

Make the non-reentrancy threadlocal. sadly that slows semaphore down to 0.5usec

parent 111affcc
...@@ -26,20 +26,31 @@ if PYPY: ...@@ -26,20 +26,31 @@ if PYPY:
def __init__(self): def __init__(self):
self._owner = None self._owner = None
self._block = _allocate_lock() self._block = _allocate_lock()
self._locking = 0 self._locking = {}
self._count = 0 self._count = 0
def untraceable(f): def untraceable(f):
# Don't allow re-entry to these functions, as can # Don't allow re-entry to these functions in a single thread, as can
# happen if a sys.settrace is used # happen if a sys.settrace is used
def wrapper(self): def wrapper(self):
if self._locking: me = _get_ident()
try:
count = self._locking[me]
except KeyError:
count = self._locking[me] = 1
else:
count = self._locking[me] = count + 1
if count:
return return
try: try:
self._locking += 1
return f(self) return f(self)
finally: finally:
self._locking -= 1 count = count - 1
if not count:
del self._locking[me]
else:
self._locking[me] = count
return wrapper return wrapper
@untraceable @untraceable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment