Package coro :: Module _coro :: Class rw_lock
[hide private]
[frames] | no frames]

Class rw_lock

object --+
         |
        rw_lock

A many-reader single-writer lock.

This lock allows multiple "readers" to own the lock simultaneously. A "writer" can only acquire a lock if there are no other "readers" or "writers" holding the lock. Readers block when acquiring the lock if a writer currently holds it.

Readers and writers may acquire the lock multiple times, but they must release the lock an equal number of times.

A thread that holds a write lock may acquire read locks, but not the other way around (holding a read lock and trying to acquire a write lock will cause a deadlock).

Instance Methods [hide private]
 
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature
a new object with type S, a subtype of T
__new__(T, S, ...)
 
read_lock(...)
Acquire a read lock.
 
read_unlock(...)
Release a read lock.
 
try_read_lock(...)
Attempt to acquire a read lock.
 
try_write_lock(...)
Attempt to acquire a write lock.
 
write_lock(...)
Acquire a write lock.
 
write_unlock(...)
Release a write lock.

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

Instance Variables [hide private]
  _reader
: Count of the number of read locks.
  _waiting_readers
: A fifo of coroutine objects waiting for a read lock.
  _waiting_writers
: A fifo of coroutine objects waiting for a write lock.
  _writer
: Count of the number of write locks.
  _writer_id
: Thread ID of the current write lock owner (0 if there is no owner).
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(...)
(Constructor)

 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

read_lock(...)

 

Acquire a read lock.

Blocks if a writer owns the lock, or if any writers are waiting for the lock. An exception is if the writer that owns the lock is the current thread.

A coro thread may acquire multiple read locks, but it must call read_unlock an equal number of times.

read_unlock(...)

 

Release a read lock.

The thread unlocking must be the thread that initially locked it.

try_read_lock(...)

 

Attempt to acquire a read lock.

This is the same as read_lock except it does not block if it cannot acquire the lock.

Returns:
Returns True if it cannot acquire the lock. Returns False if it successfully acquired the lock.

try_write_lock(...)

 

Attempt to acquire a write lock.

This is the same as write_lock except it does not block if it cannot acquire the lock.

Returns:
Returns True if it cannot acquire the lock. Returns False if it successfully acquired the lock.

write_lock(...)

 

Acquire a write lock.

This blocks if there are any other readers or writers holding the lock.

A coro thread may acquire multiple write locks, but it must call write_unlock an equal number of times.

Attempting to acquire a read lock while holding a write lock will cause a deadlock.

write_unlock(...)

 

Release a write lock.

The thread unlocking must be the thread that initially locked it.


Instance Variable Details [hide private]

_reader

: Count of the number of read locks. (C only.)

_waiting_readers

: A fifo of coroutine objects waiting for a read lock. (C only.)

_waiting_writers

: A fifo of coroutine objects waiting for a write lock. (C only.)

_writer

: Count of the number of write locks. (C only.)

_writer_id

: Thread ID of the current write lock owner (0 if there is no owner). (C only.)