Commit 1a4e32d0 authored by Guido Trotter's avatar Guido Trotter
Browse files

SharedLock _acquire_restore and _release_save



If a shared lock is used inside a condition, we need to make sure that
it's reacquired in the same way as it was originally, after the wait.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 66ecc479
......@@ -692,6 +692,14 @@ class SharedLock(object):
finally:
self.__lock.release()
def _release_save(self):
shared = self.__is_sharer()
self.release()
return shared
def _acquire_restore(self, shared):
self.acquire(shared=shared)
# Whenever we want to acquire a full LockSet we pass None as the value
# to acquire. Hide this behind this nicely named constant.
......
......@@ -698,6 +698,27 @@ class TestSharedLock(_ThreadedTestCase):
self.assertRaises(Queue.Empty, self.done.get_nowait)
class TestSharedLockInCondition(_ThreadedTestCase):
"""SharedLock as a condition lock tests"""
def setUp(self):
_ThreadedTestCase.setUp(self)
self.sl = locking.SharedLock()
self.cond = threading.Condition(self.sl)
def testKeepMode(self):
self.cond.acquire(shared=1)
self.assert_(self.sl._is_owned(shared=1))
self.cond.wait(0)
self.assert_(self.sl._is_owned(shared=1))
self.cond.release()
self.cond.acquire(shared=0)
self.assert_(self.sl._is_owned(shared=0))
self.cond.wait(0)
self.assert_(self.sl._is_owned(shared=0))
self.cond.release()
class TestSSynchronizedDecorator(_ThreadedTestCase):
"""Shared Lock Synchronized decorator test"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment