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 by calling acquire(shared=1). In order to acquire the lock in an exclusive way threads can call acquire(shared=0).

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.

Nested Classes [hide private]
  __condition_class
Group-only non-polling condition with counters.
Instance Methods [hide private]
 
__init__(self, name, monitor=None)
Construct a new SharedLock.
source code
 
GetInfo(self, fields)
Retrieves information for querying locks.
source code
 
__check_deleted(self)
Raises an exception if the lock has been deleted.
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
int
_count_pending(self)
Returns the number of pending acquires.
source code
 
__do_acquire(self, shared)
Actually acquire the lock.
source code
 
__can_acquire(self, shared)
Determine whether lock can be acquired.
source code
 
__is_on_top(self, cond)
Checks whether the passed condition is on top of the queue.
source code
 
__acquire_unlocked(self, shared, timeout)
Acquire a shared lock.
source code
 
acquire(self, shared=0, timeout=None, test_notify=None)
Acquire a shared lock.
source code
 
release(self)
Release a Shared Lock.
source code
 
delete(self, timeout=None)
Delete a Shared Lock.
source code
 
_release_save(self) source code
 
_acquire_restore(self, shared) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
string name
the name of the lock
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, monitor=None)
(Constructor)

source code 

Construct a new SharedLock.

Parameters:
  • name - the name of the lock
  • monitor (LockMonitor) - Lock monitor with which to register
Overrides: object.__init__

GetInfo(self, fields)

source code 

Retrieves information for querying locks.

Parameters:
  • fields (list of strings) - List of fields to return

__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

__is_on_top(self, cond)

source code 

Checks whether the passed condition is on top of the queue.

The caller must make sure the queue isn't empty.

__acquire_unlocked(self, shared, timeout)

source code 

Acquire a shared lock.

Parameters:
  • shared - whether to acquire in shared mode; by default an exclusive lock will be acquired
  • timeout - maximum waiting time before giving up

acquire(self, shared=0, timeout=None, test_notify=None)

source code 

Acquire a shared lock.

Parameters:
  • shared (integer (0/1) used as a boolean) - whether to acquire in shared mode; by default an exclusive lock will be acquired
  • timeout (float) - maximum waiting time before giving up
  • test_notify (callable or None) - Special callback function for unittesting

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, timeout=None)

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:
  • timeout (float) - maximum waiting time before giving up