]> git.decadent.org.uk Git - dak.git/commitdiff
split read and write locks
authorMike O'Connor <stew@vireo.org>
Fri, 30 Oct 2009 14:38:18 +0000 (15:38 +0100)
committerMike O'Connor <stew@vireo.org>
Fri, 30 Oct 2009 14:38:18 +0000 (15:38 +0100)
Signed-off-by: Mike O'Connor <stew@vireo.org>
dak/import_known_changes.py

index 0b2386263143be2fe184d09ba3c50848d7c422e2..cdb1d3afd4a150bd8d59f0676a16f8fc697cef71 100755 (executable)
@@ -128,37 +128,48 @@ class OneAtATime(object):
     """
     def __init__(self):
         self.next_in_line = None
-        self.next_lock = threading.Condition()
+        self.read_lock = threading.Condition()
+        self.write_lock = threading.Condition()
         self.die = False
 
     def plsDie(self):
         self.die = True
-        self.next_lock.notify()
+        self.write_lock.acquire()
+        self.write_lock.notifyAll()
+        self.write_lock.release()
+
+        self.read_lock.acquire()
+        self.read_lock.notifyAll()
+        self.read_lock.release()
 
     def enqueue(self, next):
-        self.next_lock.acquire()
+        self.write_lock.acquire()
         while self.next_in_line:
             if self.die:
                 return
-            self.next_lock.wait()
+            self.write_lock.wait()
 
         assert( not self.next_in_line )
         self.next_in_line = next
-        self.next_lock.notifyAll()
-        self.next_lock.release()
+        self.write_lock.release()
+        self.read_lock.acquire()
+        self.read_lock.notify()
+        self.read_lock.release()
 
     def dequeue(self):
-        self.next_lock.acquire()
+        self.read_lock.acquire()
         while not self.next_in_line:
             if self.die:
                 return
-            self.next_lock.wait()
+            self.read_lock.wait()
 
         result = self.next_in_line
 
         self.next_in_line = None
-        self.next_lock.notifyAll()
-        self.next_lock.release()
+        self.read_lock.release()
+        self.write_lock.acquire()
+        self.write_lock.notify()
+        self.write_lock.release()
 
         if isinstance(result, EndOfChanges):
             return None