summaryrefslogtreecommitdiff
path: root/realtime/rt/util.py
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-27 13:39:24 -0700
committerMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-27 13:39:24 -0700
commit6fd8326590fbe02d97ca2e897a95131b47413b09 (patch)
treebf1678cf4596a02f3b406ead14e968fca492aaad /realtime/rt/util.py
parentce358ecd6f5132f8bdbbda2272ff4f04ff883e30 (diff)
Decoding and learning with multiple contexts is threadsafe and FIFO.
Diffstat (limited to 'realtime/rt/util.py')
-rw-r--r--realtime/rt/util.py8
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