c++-gtk-utils
|
A scoped locking class for exception safe RWLock read locking. More...
#include <c++-gtk-utils/rw_lock.h>
Public Member Functions | |
int | lock () |
int | trylock () |
int | unlock () |
ReaderLock (RWLock &rw_lock_) | |
ReaderLock (RWLock &rw_lock_, Locked tag) | |
~ReaderLock () | |
A scoped locking class for exception safe RWLock read locking.
|
inline |
This constructor locks for reading the read-write lock passed to it. It is not a cancellation point.
rw_lock_ | The read-write lock to be locked for reading. |
Cgu::Thread::RWLockError | Throws this exception if initialization of the read-write lock fails because the maximum number of read locks for the particular read-write lock in question has been reached. Usually this number is at or around INT_MAX so it is not usually useful to check for the exception except during debugging. This exception may also be thrown if the thread constructing this object already holds a write lock on the read-write lock in question. It will do this if the default pthread implementation returns EDEADLK in such a case instead of deadlocking. However as most default implementations will simply deadlock in such circumstances, it is usually not worth checking for this either except during debugging. |
Since 1.2.1
This constructor takes a read-write lock already locked for reading (say as a result of RWLock::reader_trylock()), and takes management of that read lock operation. It is not a cancellation point. It does not throw.
rw_lock_ | The read-write lock to be managed for reading by this object. |
tag | Pass the Cgu::Thread::locked enum tag to this parameter. |
Since 1.2.1
|
inline |
The destructor unlocks the read-write lock which is managed for reading. It is not a cancellation point. It does not throw.
Since 1.2.1
|
inline |
Calls RWLock::reader_lock(), and so relocks the read-write lock for reading. It blocks if the read-write lock is already locked for writing until it becomes free. This method should normally only be called if a previous call has been made to RWLock::ReaderLock::unlock() (that is, where the thread owning the RWLock::ReaderLock object has temporarily allowed another thread to take the read-write lock concerned for writing if another thread does not hold a read lock or the read-write lock has not been recursively locked for reading). It is not a cancellation point. It does not throw.
Since 1.2.1
|
inline |
Calls RWLock::reader_trylock(), and so tries to relock the read-write lock for reading, but returns immediately with value EBUSY if it is already locked for writing. This method should normally only be called if a previous call has been made to RWLock::ReaderLock::unlock() (that is, where the thread owning the RWLock::ReaderLock object has temporarily allowed another thread to take the read-write lock concerned for writing if another thread does not hold a read lock or the read-write lock has not been recursively locked for reading). It is not a cancellation point. It does not throw.
Since 1.2.1
|
inline |
Calls RWLock::unlock(), and so unlocks a locked read-write lock held by the calling thread for reading (so temporarily allowing another thread to take the read-write lock for writing should no other read lock be held or the particular implementation provides writer priority). This method should normally only be called if it is to be followed by a call to RWLock::ReaderLock::lock() or a successful call to RWLock::ReaderLock::trylock() before the RWLock::ReaderLock object concerned goes out of scope (otherwise RWLock::ReaderLock's destructor will attempt to unlock an already unlocked read-write lock or a read-write lock of which another thread holds a lock - RWLock::ReaderLock objects do not maintain state). See RWLock::ReaderTrackLock::unlock() for a safe version of this method. It is not a cancellation point. It does not throw.
Since 1.2.1