summaryrefslogtreecommitdiff
path: root/realtime/rt/util.py
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-26 14:28:42 -0700
committerMichael Denkowski <mdenkows@cs.cmu.edu>2013-09-26 14:28:42 -0700
commitcb718c763e07b8e1417383ef7ae5c1aca36d2a0a (patch)
tree2c4495650f59ab6b085ff95cef25bb05776232a8 /realtime/rt/util.py
parent49ddc45e717ac495c6adf80a20d02a1672a069df (diff)
FIFO Locks
Diffstat (limited to 'realtime/rt/util.py')
-rw-r--r--realtime/rt/util.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/realtime/rt/util.py b/realtime/rt/util.py
index 6e07f116..05dcae96 100644
--- a/realtime/rt/util.py
+++ b/realtime/rt/util.py
@@ -1,4 +1,5 @@
import os
+import Queue
import subprocess
import sys
import threading
@@ -13,6 +14,24 @@ SA_INI_FILES = set((
'precompute_file',
))
+class FIFOLock:
+
+ def __init__(self):
+ self.q = Queue.Queue()
+ self.i = 0
+
+ def acquire(self):
+ self.i += 1
+ if self.i > 1:
+ event = threading.Event()
+ self.q.put(event)
+ event.wait()
+
+ def release(self):
+ self.i -= 1
+ if self.i > 0:
+ self.q.get().set()
+
def cdec_ini_for_config(config):
# This is a list of (k, v), not a ConfigObj or dict
for i in range(len(config)):