Commit d4803c24 authored by Guido Trotter's avatar Guido Trotter
Browse files

Fix LockSet._names() to work with the set-lock

If the set-lock is acquired, currently, the _names function will fail on
a double acquire of a non-recursive lock. This patch fixes the behavior,
and some lines of code added to the testAcquireSetLock test check that
this and other functioins behave properly.

Reviewed-by: imsnah
parent aefef4f4
...@@ -390,11 +390,17 @@ class LockSet: ...@@ -390,11 +390,17 @@ class LockSet:
Used only for debugging purposes. Used only for debugging purposes.
""" """
self.__lock.acquire(shared=1) # If we don't already own the set-level lock acquired
# we'll get it and note we need to release it later.
release_lock = False
if not self.__lock._is_owned():
release_lock = True
self.__lock.acquire(shared=1)
try: try:
result = self.__names() result = self.__names()
finally: finally:
self.__lock.release() if release_lock:
self.__lock.release()
return set(result) return set(result)
def acquire(self, names, blocking=1, shared=0): def acquire(self, names, blocking=1, shared=0):
......
...@@ -393,6 +393,9 @@ class TestLockSet(unittest.TestCase): ...@@ -393,6 +393,9 @@ class TestLockSet(unittest.TestCase):
def testAcquireSetLock(self): def testAcquireSetLock(self):
# acquire the set-lock exclusively # acquire the set-lock exclusively
self.assertEquals(self.ls.acquire(None), set(['one', 'two', 'three'])) self.assertEquals(self.ls.acquire(None), set(['one', 'two', 'three']))
self.assertEquals(self.ls._list_owned(), set(['one', 'two', 'three']))
self.assertEquals(self.ls._is_owned(), True)
self.assertEquals(self.ls._names(), set(['one', 'two', 'three']))
# I can still add/remove elements... # I can still add/remove elements...
self.assertEquals(self.ls.remove(['two', 'three']), ['two', 'three']) self.assertEquals(self.ls.remove(['two', 'three']), ['two', 'three'])
self.assert_(self.ls.add('six')) self.assert_(self.ls.add('six'))
......
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