Commit 19d17982 authored by David Wilson's avatar David Wilson

core: Split blocking and non-blocking Latch.get()

Mostly just to avoid embarrassing function size, but it may come in
useful for testing later.
parent cba33475
...@@ -943,7 +943,11 @@ class Latch(object): ...@@ -943,7 +943,11 @@ class Latch(object):
finally: finally:
self._lock.release() self._lock.release()
_vv and IOLOG.debug('%r.get() -> sleeping', self) return self._get_sleep(timeout, block)
def _get_sleep(self, timeout, block):
_vv and IOLOG.debug('%r._get_sleep(timeout=%r, block=%r)',
self, timeout, block)
e = None e = None
try: try:
io_op(select.select, [_tls.rsock], [], [], timeout) io_op(select.select, [_tls.rsock], [], [], timeout)
...@@ -954,10 +958,9 @@ class Latch(object): ...@@ -954,10 +958,9 @@ class Latch(object):
try: try:
i = self._sleeping.index(_tls.wsock) i = self._sleeping.index(_tls.wsock)
del self._sleeping[i] del self._sleeping[i]
if i < self._waking: if i >= self._waking:
self._waking -= 1
else:
raise TimeoutError() raise TimeoutError()
self._waking -= 1
if _tls.rsock.recv(2) != '\x7f': if _tls.rsock.recv(2) != '\x7f':
raise LatchError('internal error: received >1 wakeups') raise LatchError('internal error: received >1 wakeups')
if e: if e:
......
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