Package ganeti :: Module locking :: Class SharedLock
[hide private]
[frames] | no frames]

Class SharedLock

source code

Implements a shared lock.

Multiple threads can acquire the lock in a shared way, calling acquire_shared(). In order to acquire the lock in an exclusive way threads can call acquire_exclusive().

The lock prevents starvation but does not guarantee that threads will acquire the shared lock in the order they queued for it, just that they will eventually do so.

Instance Methods [hide private]
 
__init__(self)
Construct a new SharedLock
source code
 
__is_sharer(self)
Is the current thread sharing the lock at this time?
source code
 
__is_exclusive(self)
Is the current thread holding the lock exclusively at this time?
source code
 
__is_owned(self, shared=-1)
Is the current thread somehow owning the lock at this time?
source code
 
_is_owned(self, shared=-1)
Is the current thread somehow owning the lock at this time?
source code
 
__wait(self, c)
Wait on the given condition, and raise an exception if the current lock is declared deleted in the meantime.
source code
 
__exclusive_acquire(self)
Acquire the lock exclusively.
source code
 
acquire(self, blocking=1, shared=0)
Acquire a shared lock.
source code
 
release(self)
Release a Shared Lock.
source code
 
delete(self, blocking=1)
Delete a Shared Lock.
source code
Method Details [hide private]

__is_owned(self, shared=-1)

source code 

Is the current thread somehow owning the lock at this time?

This is a private version of the function, which presumes you're holding the internal lock.

_is_owned(self, shared=-1)

source code 

Is the current thread somehow owning the lock at this time?

Parameters:
  • shared -
    • < 0: check for any type of ownership (default)
    • 0: check for exclusive ownership
    • > 0: check for shared ownership

__wait(self, c)

source code 

Wait on the given condition, and raise an exception if the current lock is declared deleted in the meantime.

Parameters:
  • c - the condition to wait on

__exclusive_acquire(self)

source code 

Acquire the lock exclusively.

This is a private function that presumes you are already holding the internal lock. It's defined separately to avoid code duplication between acquire() and delete()

acquire(self, blocking=1, shared=0)

source code 

Acquire a shared lock.

Parameters:
  • shared - whether to acquire in shared mode; by default an exclusive lock will be acquired
  • blocking - whether to block while trying to acquire or to operate in try-lock mode (this locking mode is not supported yet)

release(self)

source code 

Release a Shared Lock.

You must have acquired the lock, either in shared or in exclusive mode, before calling this function.

delete(self, blocking=1)

source code 

Delete a Shared Lock.

This operation will declare the lock for removal. First the lock will be acquired in exclusive mode if you don't already own it, then the lock will be put in a state where any future and pending acquire() fail.

Parameters:
  • blocking - whether to block while trying to acquire or to operate in try-lock mode. this locking mode is not supported yet unless you are already holding exclusively the lock.