diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-09 11:35:41 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-09 11:35:41 +0200 |
commit | 1090701721888474d34f8a4af28ee1bb1c3fdaaa (patch) | |
tree | 2a2a8cec9b2e3bcfac3125ab13afc1e225f2b32a /lib/git/async/util.py | |
parent | 2054561da184955c4be4a92f0b4fa5c5c1c01350 (diff) | |
download | gitpython-1090701721888474d34f8a4af28ee1bb1c3fdaaa.tar.gz |
HSCondition: now deriving from deque, as the AsyncQeue does, to elimitate one more level of indirection. Clearly this not good from a design standpoint, as a Condition is no Deque, but it helps speeding things up which is what this is about. Could make it a hidden class to indicate how 'special' it is
Diffstat (limited to 'lib/git/async/util.py')
-rw-r--r-- | lib/git/async/util.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/git/async/util.py b/lib/git/async/util.py index 2c18a1b9..ffdb14a2 100644 --- a/lib/git/async/util.py +++ b/lib/git/async/util.py @@ -69,17 +69,16 @@ class SyncQueue(deque): put = deque.append -class HSCondition(object): +class HSCondition(deque): """Cleaned up code of the original condition object in order to make it run and respond faster.""" - __slots__ = ("_lock", '_waiters') + __slots__ = ("_lock") delay = 0.0002 # reduces wait times, but increases overhead def __init__(self, lock=None): if lock is None: lock = Lock() self._lock = lock - self._waiters = deque() def release(self): self._lock.release() @@ -93,7 +92,7 @@ class HSCondition(object): def wait(self, timeout=None): waiter = _allocate_lock() waiter.acquire() # get it the first time, no blocking - self._waiters.append(waiter) + self.append(waiter) # in the momemnt we release our lock, someone else might actually resume self.release() @@ -124,7 +123,7 @@ class HSCondition(object): # END endless loop if not gotit: try: - self._waiters.remove(waiter) + self.remove(waiter) except ValueError: pass # END didn't ever get it @@ -140,13 +139,13 @@ class HSCondition(object): In the multi-notify case, we acquire a lock just for safety, as otherwise we might pop too much of someone else notifies n waiters as well, which would in the worst case lead to double-releases of locks.""" - if not self._waiters: + if not self: return if n == 1: # so here we assume this is thead-safe ! It wouldn't be in any other # language, but python it is. try: - self._waiters.popleft().release() + self.popleft().release() except IndexError: pass else: @@ -155,8 +154,8 @@ class HSCondition(object): # and waits again, but only until we are done, which is important # to do that in a thread-safe fashion try: - for i in range(min(n, len(self._waiters))): - self._waiters.popleft().release() + for i in range(min(n, len(self))): + self.popleft().release() # END for each waiter to resume finally: self.release() @@ -164,7 +163,7 @@ class HSCondition(object): # END handle n = 1 case faster def notify_all(self): - self.notify(len(self._waiters)) + self.notify(len(self)) class ReadOnly(Exception): |