Skip to content

Commit a988e69

Browse files
committed
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
1 parent 1090701 commit a988e69

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/git/async/util.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def wait(self, timeout=None):
9595
self.append(waiter)
9696

9797
# in the momemnt we release our lock, someone else might actually resume
98-
self.release()
98+
self._lock.release()
9999
try: # restore state no matter what (e.g., KeyboardInterrupt)
100100
# now we block, as we hold the lock already
101101
if timeout is None:
@@ -129,7 +129,7 @@ def wait(self, timeout=None):
129129
# END didn't ever get it
130130
finally:
131131
# reacquire the lock
132-
self.acquire()
132+
self._lock.acquire()
133133
# END assure release lock
134134

135135
def notify(self, n=1):
@@ -144,12 +144,23 @@ def notify(self, n=1):
144144
if n == 1:
145145
# so here we assume this is thead-safe ! It wouldn't be in any other
146146
# language, but python it is.
147+
# But ... its two objects here - first the popleft, then the relasecall.
148+
# If the timing is really really bad, and that happens if you let it
149+
# run often enough ( its a matter of statistics ), this will fail,
150+
# which is why we lock it.
151+
# And yes, this causes some slow down, as single notifications happen
152+
# alot
153+
self._lock.acquire()
147154
try:
148-
self.popleft().release()
149-
except IndexError:
150-
pass
155+
try:
156+
self.popleft().release()
157+
except IndexError:
158+
pass
159+
finally:
160+
self._lock.release()
161+
# END assure lock is released
151162
else:
152-
self.acquire()
163+
self._lock.acquire()
153164
# once the waiter resumes, he will want to acquire the lock
154165
# and waits again, but only until we are done, which is important
155166
# to do that in a thread-safe fashion
@@ -158,7 +169,7 @@ def notify(self, n=1):
158169
self.popleft().release()
159170
# END for each waiter to resume
160171
finally:
161-
self.release()
172+
self._lock.release()
162173
# END assure we release our lock
163174
# END handle n = 1 case faster
164175

0 commit comments

Comments
 (0)