libcommonc++
0.7
|
A Read/Write lock – a synchronization primitive that allows multiple threads to coordinate access to a mutable resource. More...
#include <ReadWriteLock.h++>
Public Member Functions | |
ReadWriteLock () | |
Construct a new ReadWriteLock. More... | |
~ReadWriteLock () | |
Destructor. More... | |
void | lockRead () |
Acquire a read lock, blocking until the lock is acquired. More... | |
bool | tryLockRead (timespan_ms_t timeout=0) |
Try to acquire a read lock, returning if the lock could not be acquired within the given amount of time. More... | |
void | lockWrite () |
Acquire a write lock, blocking until the lock is acquired. More... | |
bool | tryLockWrite (timespan_ms_t timeout=0) |
Try to acquire a write lock, returning if the lock could not be acquired within the given amount of time. More... | |
void | unlock () |
Release the lock. More... | |
Static Public Member Functions | |
static bool | supportsTimedLocks () |
Determine if the host system supports timed read/write locks. More... | |
A Read/Write lock – a synchronization primitive that allows multiple threads to coordinate access to a mutable resource.
Any number of threads can simultaneously hold the read lock as long as no thread holds the write lock. Conversely, a thread can acquire the write lock as long as no threads are holding the read lock.
See also ScopedReadLock and ScopedWriteLock.
ReadWriteLock | ( | ) |
Construct a new ReadWriteLock.
~ReadWriteLock | ( | ) |
Destructor.
void lockRead | ( | ) |
Acquire a read lock, blocking until the lock is acquired.
void lockWrite | ( | ) |
Acquire a write lock, blocking until the lock is acquired.
|
static |
Determine if the host system supports timed read/write locks.
bool tryLockRead | ( | timespan_ms_t | timeout = 0 | ) |
Try to acquire a read lock, returning if the lock could not be acquired within the given amount of time.
On platforms that do not support timed read/write locks, the method returns immediately if the lock could not be acquired.
timeout | The timeout, in milliseconds. |
bool tryLockWrite | ( | timespan_ms_t | timeout = 0 | ) |
Try to acquire a write lock, returning if the lock could not be acquired within the given amount of time.
On platforms that do not support timed read/write locks, the method returns immediately if the lock could not be acquired.
timeout | The timeout, in milliseconds. |
void unlock | ( | ) |
Release the lock.