UCommon
|
A generic and portable implimentation of Read/Write locking. More...
#include <thread.h>
Data Structures | |
class | guard_reader |
Guard class to apply scope based access locking to objects. More... | |
class | guard_writer |
Guard class to apply scope based exclusive locking to objects. More... | |
Public Member Functions | |
bool | access (timeout_t timeout=Timer::inf) |
Request shared (read) access through the lock. | |
bool | modify (timeout_t timeout=Timer::inf) |
Request modify (write) access through the lock. | |
void | release (void) |
Release the lock. | |
ThreadLock () | |
Create an instance of a rwlock. | |
Static Public Member Functions | |
static void | indexing (unsigned size) |
Specify hash table size for guard protection. | |
static bool | reader (const void *object, timeout_t timeout=Timer::inf) |
Shared access to an arbitrary object. | |
static bool | release (const void *object) |
Release an arbitrary object that has been protected by a rwlock. | |
static bool | writer (const void *object, timeout_t timeout=Timer::inf) |
Write protect access to an arbitrary object. | |
Protected Member Functions | |
virtual void | _lock (void) |
virtual void | _share (void) |
Access interface to share lock the object. | |
virtual void | _unlock (void) |
Protected Attributes | |
pthread_t | writeid |
unsigned | writers |
A generic and portable implimentation of Read/Write locking.
This class impliments 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 implimetations 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 implimented to support exclusive_lock and shared_lock referencing.
bool ucommon::ThreadLock::access | ( | timeout_t | timeout = Timer::inf | ) |
Request shared (read) access through the lock.
timeout | in milliseconds to wait for lock. |
static void ucommon::ThreadLock::indexing | ( | unsigned | size | ) | [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::ThreadLock::modify | ( | timeout_t | timeout = Timer::inf | ) |
Request modify (write) access through the lock.
timeout | in milliseconds to wait for lock. |
static bool ucommon::ThreadLock::reader | ( | const void * | object, |
timeout_t | timeout = Timer::inf |
||
) | [static] |
Shared access to an arbitrary object.
This is based on the protect function of mutex.
object | to share. |
timeout | in milliseconds to wait for lock. |
static bool ucommon::ThreadLock::release | ( | const void * | object | ) | [static] |
Release an arbitrary object that has been protected by a rwlock.
object | to release. |
static bool ucommon::ThreadLock::writer | ( | const void * | object, |
timeout_t | timeout = Timer::inf |
||
) | [static] |
Write protect access to an arbitrary object.
This is like the protect function of mutex.
object | to protect. |
timeout | in milliseconds to wait for lock. |