Commit 9216a9f7 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

locking: Acquire SharedLock in shared mode in separate function



This is for some more symetry with
SharedLock.__exclusive_acquire.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent fe89794e
......@@ -153,29 +153,13 @@ class SharedLock:
assert self.__npass_shr == 0, "SharedLock: internal fairness violation"
def acquire(self, blocking=1, shared=0):
"""Acquire a shared lock.
def __shared_acquire(self):
"""Acquire the lock in shared mode
@param shared: whether to acquire in shared mode; by default an
exclusive lock will be acquired
@param blocking: whether to block while trying to acquire or to
operate in try-lock mode (this locking mode is not supported yet)
This is a private function that presumes you are already holding the
internal lock.
"""
if not blocking:
# We don't have non-blocking mode for now
raise NotImplementedError
self.__lock.acquire()
try:
if self.__deleted:
raise errors.LockError('deleted lock')
# We cannot acquire the lock if we already have it
assert not self.__is_owned(), "double acquire() on a non-recursive lock"
assert self.__npass_shr >= 0, "Internal fairness condition weirdness"
if shared:
self.__nwait_shr += 1
try:
wait = False
......@@ -203,6 +187,31 @@ class SharedLock:
self.__nwait_shr -= 1
assert self.__npass_shr >= 0, "Internal fairness condition weirdness"
def acquire(self, blocking=1, shared=0):
"""Acquire a shared lock.
@param shared: whether to acquire in shared mode; by default an
exclusive lock will be acquired
@param blocking: whether to block while trying to acquire or to
operate in try-lock mode (this locking mode is not supported yet)
"""
if not blocking:
# We don't have non-blocking mode for now
raise NotImplementedError
self.__lock.acquire()
try:
if self.__deleted:
raise errors.LockError('deleted lock')
# We cannot acquire the lock if we already have it
assert not self.__is_owned(), "double acquire() on a non-recursive lock"
assert self.__npass_shr >= 0, "Internal fairness condition weirdness"
if shared:
self.__shared_acquire()
else:
# TODO: if !blocking...
# (or modify __exclusive_acquire for non-blocking mode)
......@@ -353,7 +362,6 @@ class LockSet:
else:
self.__owners[threading.currentThread()] = set([name])
def _del_owned(self, name=None):
"""Note the current thread owns the given lock"""
......
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