diff options
author | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-27 13:39:24 -0700 |
---|---|---|
committer | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-27 13:39:24 -0700 |
commit | b8116c5c3c7e31a276ff38fc8173eab37f292364 (patch) | |
tree | 249a8a368680c177251f6b41689e5b5739ee5da8 /realtime/rt/util.py | |
parent | cb718c763e07b8e1417383ef7ae5c1aca36d2a0a (diff) |
Decoding and learning with multiple contexts is threadsafe and FIFO.
Diffstat (limited to 'realtime/rt/util.py')
-rw-r--r-- | realtime/rt/util.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/realtime/rt/util.py b/realtime/rt/util.py index 05dcae96..52767dac 100644 --- a/realtime/rt/util.py +++ b/realtime/rt/util.py @@ -15,22 +15,30 @@ SA_INI_FILES = set(( )) class FIFOLock: + '''Lock that preserves FIFO order of blocking threads''' def __init__(self): self.q = Queue.Queue() self.i = 0 + self.lock = threading.Lock() def acquire(self): + self.lock.acquire() self.i += 1 if self.i > 1: event = threading.Event() self.q.put(event) + self.lock.release() event.wait() + return + self.lock.release() def release(self): + self.lock.acquire() self.i -= 1 if self.i > 0: self.q.get().set() + self.lock.release() def cdec_ini_for_config(config): # This is a list of (k, v), not a ConfigObj or dict |