c++-gtk-utils
|
A scoped locking class for exception safe RWLock read locking which tracks the status of its read-write lock. More...
#include <c++-gtk-utils/rw_lock.h>
Public Member Functions | |
int | lock () |
int | trylock () |
int | unlock () |
bool | is_owner () const |
ReaderTrackLock (RWLock &rw_lock_) | |
ReaderTrackLock (RWLock &rw_lock_, Locked tag) | |
ReaderTrackLock (RWLock &rw_lock_, DeferLock tag) | |
~ReaderTrackLock () | |
A scoped locking class for exception safe RWLock read locking which tracks the status of its read-write lock.
This class is similar to a RWLock::ReaderLock object, except that it tracks whether the read-write lock it manages is locked for reading by the thread creating the RWLock::ReaderTrackLock object with respect to the particular read-locking operation to be governed by the object (provided that, while the RWLock::ReaderTrackLock object exists, the thread creating it only accesses the managed read-write lock with respect that particular operation through that object). This enables RWLock::ReaderTrackLock::unlock() to be used without it being followed later by a call to RWLock::ReaderTrackLock::lock() or a successful call to RWLock::ReaderTrackLock::trylock(), and also permits locking to be deferred until after construction of the RWLock::ReaderTrackLock object. Note that only one thread may call the methods of any one RWLock::ReaderTrackLock object, including causing its destructor to be invoked.
|
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
This constructor defers locking of the read-write lock for reading until an explicit call to lock() or trylock() is made. 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::defer enum tag to this parameter. |
Since 1.2.1
|
inline |
The destructor unlocks the read-write lock which is managed for reading if it is owned by this RWLock::ReaderTrackLock object (whether solely or with other read locks). It is not a cancellation point. It does not throw.
Since 1.2.1
|
inline |
Indicates whether the read-write lock managed by this RWLock::ReaderTrackLock object is locked for reading by it and so owned by it (whether solely or with other read locks). It does not throw.
Since 1.2.1
|
inline |
This calls RWLock::reader_lock(), and so locks the read-write lock for reading and acquires ownership (which may be shared with other read locks). 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::ReaderTrackLock::unlock() or this RWLock::ReaderTrackLock object has been constructed with the Thread::defer enum tag. It is not a cancellation point. It does not throw.
Since 1.2.1
|
inline |
This calls RWLock::reader_trylock(), and so tries to lock the read-write lock for reading and acquire ownership (which may be shared with other read locks), 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::ReaderTrackLock::unlock() or this RWLock::ReaderTrackLock object has been constructed with the Thread::defer enum tag. It is not a cancellation point. It does not throw.
Since 1.2.1
|
inline |
This calls RWLock::unlock(), and so unlocks a locked read-write lock held by the calling thread for reading and relinquishes ownership (whether it was sole or shared with other read locks). It will cause is_owner() to return false unless a subsequent call is made to lock() or a subsequent successful call is made to trylock(). It is not a cancellation point. It does not throw.
Since 1.2.1