diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-09 11:45:25 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-09 11:45:25 +0200 |
commit | a988e6985849e4f6a561b4a5468d525c25ce74fe (patch) | |
tree | 2e8c8a4cf633a1c6511f5285c2cc1aed2c043eb9 /lib/git | |
parent | 1090701721888474d34f8a4af28ee1bb1c3fdaaa (diff) | |
download | gitpython-a988e6985849e4f6a561b4a5468d525c25ce74fe.tar.gz |
HSCondition: now gets a lock even in the single-notify case, as it was required due to the non-atomiciy of the invovled operation. Removed one level of indirection for the lock, by refraining from calling my own 'wrapper' methods, which brought it back to the performance it had before the locking was introduced for the n==1 case
Diffstat (limited to 'lib/git')
-rw-r--r-- | lib/git/async/util.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/git/async/util.py b/lib/git/async/util.py index ffdb14a2..008e60a3 100644 --- a/lib/git/async/util.py +++ b/lib/git/async/util.py @@ -95,7 +95,7 @@ class HSCondition(deque): self.append(waiter) # in the momemnt we release our lock, someone else might actually resume - self.release() + self._lock.release() try: # restore state no matter what (e.g., KeyboardInterrupt) # now we block, as we hold the lock already if timeout is None: @@ -129,7 +129,7 @@ class HSCondition(deque): # END didn't ever get it finally: # reacquire the lock - self.acquire() + self._lock.acquire() # END assure release lock def notify(self, n=1): @@ -144,12 +144,23 @@ class HSCondition(deque): if n == 1: # so here we assume this is thead-safe ! It wouldn't be in any other # language, but python it is. + # But ... its two objects here - first the popleft, then the relasecall. + # If the timing is really really bad, and that happens if you let it + # run often enough ( its a matter of statistics ), this will fail, + # which is why we lock it. + # And yes, this causes some slow down, as single notifications happen + # alot + self._lock.acquire() try: - self.popleft().release() - except IndexError: - pass + try: + self.popleft().release() + except IndexError: + pass + finally: + self._lock.release() + # END assure lock is released else: - self.acquire() + self._lock.acquire() # once the waiter resumes, he will want to acquire the lock # and waits again, but only until we are done, which is important # to do that in a thread-safe fashion @@ -158,7 +169,7 @@ class HSCondition(deque): self.popleft().release() # END for each waiter to resume finally: - self.release() + self._lock.release() # END assure we release our lock # END handle n = 1 case faster |