UCommon
|
A generic and portable implementation of Read/Write locking. More...
#include <thread.h>
Data Structures | |
class | reader |
Apply automatic scope based access locking to objects. More... | |
class | writer |
Apply automatic scope based exclusive locking to objects. More... | |
Public Types | |
typedef autoshared< RWLock > | autoreader |
typedef autoexclusive< RWLock > | autowriter |
Public Member Functions | |
bool | access (timeout_t timeout=Timer::inf) |
Request shared (read) access through the lock. More... | |
bool | modify (timeout_t timeout=Timer::inf) |
Request modify (write) access through the lock. More... | |
void | release (void) |
Release the lock. | |
RWLock () | |
Create an instance of a rwlock. | |
![]() | |
virtual void | exclusive (void) |
Convert object to an exclusive lock. More... | |
virtual void | share (void) |
Share the lock with other referencers. More... | |
Static Public Member Functions | |
static void | indexing (unsigned size) |
Specify hash table size for guard protection. More... | |
static bool | release (const void *object) |
Release an arbitrary object that has been protected by a rwlock. More... | |
Protected Member Functions | |
virtual void | _lock (void) |
virtual void | _share (void) |
Access interface to share lock the object. | |
virtual void | _unlock (void) |
virtual void | _unshare (void) |
Protected Attributes | |
pthread_t | writeid |
unsigned | writers |
Additional Inherited Members | |
![]() | |
void | access (void) |
Access mode shared thread scheduling. | |
void | commit (void) |
Complete exclusive mode write scheduling. | |
ConditionalAccess () | |
Initialize and construct conditional. | |
void | limit_sharing (unsigned max) |
Specify a maximum sharing (access) limit. More... | |
void | modify (void) |
Exclusive mode write thread scheduling. | |
void | release (void) |
Release access mode read scheduling. | |
~ConditionalAccess () | |
Destroy conditional, release any blocked threads. | |
void | broadcast (void) |
Signal the conditional to release all broadcast threads. | |
void | lock (void) |
Lock the conditional's supporting mutex. | |
void | signal (void) |
Signal the conditional to release one signalled thread. | |
void | unlock (void) |
Unlock the conditional's supporting mutex. | |
bool | waitBroadcast (timeout_t timeout) |
Conditional wait for broadcast on millisecond timeout. More... | |
bool | waitBroadcast (struct timespec *timeout) |
Conditional wait for broadcast on timespec timeout. More... | |
void | waitBroadcast (void) |
Wait (block) until broadcast. | |
bool | waitSignal (timeout_t timeout) |
Conditional wait for signal on millisecond timeout. More... | |
bool | waitSignal (struct timespec *timeout) |
Conditional wait for signal on timespec timeout. More... | |
void | waitSignal (void) |
Wait (block) until signalled. | |
A generic and portable implementation of Read/Write locking.
This class implements classical read/write locking, including "timed" locks. Support for scheduling threads to avoid writer starvation is also provided for. By building read/write locks from a conditional, we make them available on pthread implemetations and other platforms which do not normally include optional pthread rwlock's. We also do not restrict the number of threads that may use the lock. Finally, both the exclusive and shared protocols are implemented to support exclusive_lock and shared_lock referencing. Because of the thread locking semantics this is part of thread rather than condition, and was originally called ThreadLock in older ucommon/commoncpp releases. Our autolock semantics are also different as we protect a target object, not a rwlock instance.
bool ucommon::RWLock::access | ( | timeout_t | timeout = Timer::inf | ) |
Request shared (read) access through the lock.
timeout | in milliseconds to wait for lock. |
|
static |
Specify hash table size for guard protection.
The default is 1. This should be called at initialization time from the main thread of the application before any other threads are created.
size | of hash table used for guarding. |
bool ucommon::RWLock::modify | ( | timeout_t | timeout = Timer::inf | ) |
Request modify (write) access through the lock.
timeout | in milliseconds to wait for lock. |
|
static |
Release an arbitrary object that has been protected by a rwlock.
object | to release. |