locking: Notify only once on release
authorMichael Hanselmann <hansmi@google.com>
Wed, 21 Mar 2012 15:21:36 +0000 (16:21 +0100)
committerMichael Hanselmann <hansmi@google.com>
Thu, 22 Mar 2012 13:03:32 +0000 (14:03 +0100)
Don't notify for every released lock in shared mode. The last one is
enough.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Bernardo Dal Seno <bdalseno@google.com>

lib/locking.py

index 5d5a01d..9c14ae3 100644 (file)
@@ -804,11 +804,15 @@ class SharedLock(object):
       # Autodetect release type
       if self.__is_exclusive():
         self.__exc = None
+        notify = True
       else:
         self.__shr.remove(threading.currentThread())
+        notify = not self.__shr
 
-      # Notify topmost condition in queue
-      self.__notify_topmost()
+      # Notify topmost condition in queue if there are no owners left (for
+      # shared locks)
+      if notify:
+        self.__notify_topmost()
     finally:
       self.__lock.release()