Useful return with RWLock release
authorJack Miller <jack@codezen.org>
Tue, 21 Jul 2015 16:09:22 +0000 (11:09 -0500)
committerJack Miller <jack@codezen.org>
Wed, 22 Jul 2015 03:20:30 +0000 (22:20 -0500)
Will return True if the lock should be fully released.

canto_next/rwlock.py

index 5621147..be5dc64 100644 (file)
@@ -71,6 +71,8 @@ class RWLock(object):
         return True
 
     def release_read(self):
+        last = False
+
         self.reader_lock.acquire()
         self.readers -= 1
 
@@ -79,7 +81,11 @@ class RWLock(object):
                 self.reader_stacks.remove(tup)
                 break
 
+        if self.readers == 0:
+            last = True
+
         self.reader_lock.release()
+        return last
 
     def acquire_write(self, block=True):
         r = self.lock.acquire(block)
@@ -107,11 +113,17 @@ class RWLock(object):
         return True
 
     def release_write(self):
+        last = False
+
         self.writer_stacks = self.writer_stacks[0:-1]
         if self.writer_stacks == []:
             self.writer_id = 0
+            last = True
+
         self.lock.release()
 
+        return last
+
 def read_lock(lock):
     def _rlock_fn(fn):
         def _rlock(*args, **kwargs):