An optimized and convertable shared lock. More...
#include <thread.h>
Public Member Functions | |
void | access (void) |
Acquire access (shared read) lock. | |
void | commit (void) |
Commit changes / release a modify lock. | |
ConditionalLock () | |
Construct conditional lock for default concurrency. | |
void | exclusive (void) |
Convert read lock into exclusive (write/modify) access. | |
unsigned | getReaders (void) |
Get the number of threads reading (sharing) the lock. | |
unsigned | getWaiters (void) |
Get the number of threads waiting to share the lock. | |
void | modify (void) |
Acquire write (exclusive modify) lock. | |
void | release (void) |
Release a shared lock. | |
void | share (void) |
Return an exclusive access lock back to share mode. | |
~ConditionalLock () | |
Destroy conditional lock. | |
Static Public Member Functions | |
static void | access (ConditionalLock &lock) |
Convenience function to aqcuire a shared lock. | |
static void | commit (ConditionalLock &lock) |
Convenience function to commit a modify lock. | |
static void | exclusive (ConditionalLock &lock) |
Convenience function to convert lock to exclusive mode. | |
static void | modify (ConditionalLock &lock) |
Convenience function to modify lock. | |
static void | release (ConditionalLock &lock) |
Convenience function to release a shared lock. | |
static void | share (ConditionalLock &lock) |
Convenience function to convert lock to shared access. | |
Protected Member Functions | |
void | Exclusive (void) |
Convert object to an exclusive lock. | |
Context * | getContext (void) |
void | Share (void) |
Share the lock with other referencers. | |
void | Shlock (void) |
Protocol interface to share lock the object. | |
void | Unlock (void) |
Protocol interface to release a lock. | |
Protected Attributes | |
LinkedObject * | contexts |
An optimized and convertable shared lock.
This is a form of read/write lock that has been optimized, particularly for shared access. Support for scheduling access around writer starvation is also included. The other benefits over traditional read/write locks is that the code is a little lighter, and read (shared) locks can be converted to exclusive (write) locks to perform brief modify operations and then returned to read locks, rather than having to release and re-aquire locks to change mode.
Definition at line 806 of file thread.h.
static void ucommon::ConditionalLock::access | ( | ConditionalLock & | lock | ) | [inline, static] |
static void ucommon::ConditionalLock::commit | ( | ConditionalLock & | lock | ) | [inline, static] |
static void ucommon::ConditionalLock::exclusive | ( | ConditionalLock & | lock | ) | [inline, static] |
void ucommon::ConditionalLock::exclusive | ( | void | ) |
Convert read lock into exclusive (write/modify) access.
Schedule when other readers sharing.
void ucommon::ConditionalLock::Exclusive | ( | void | ) | [protected, virtual] |
Convert object to an exclusive lock.
Many of our shared locking objects such as the "conditional lock" support the ability to switch between shared and exclusive locking modes. This derived protocol member allows one to temporarily assert exclusive locking when tied to such methods.
Reimplemented from ucommon::SharedProtocol.
static void ucommon::ConditionalLock::modify | ( | ConditionalLock & | lock | ) | [inline, static] |
static void ucommon::ConditionalLock::release | ( | ConditionalLock & | lock | ) | [inline, static] |
static void ucommon::ConditionalLock::share | ( | ConditionalLock & | lock | ) | [inline, static] |
void ucommon::ConditionalLock::Share | ( | void | ) | [protected, virtual] |
Share the lock with other referencers.
Many of our shared locking objects support the ability to switch between shared and exclusive mode. This derived protocol member allows one to restore the lock to shared mode after it has been made exclusive.
Reimplemented from ucommon::SharedProtocol.