c++-gtk-utils
|
A scoped locking class for exception safe RWLock write locking. More...
#include <c++-gtk-utils/rw_lock.h>
Public Member Functions | |
WriterLock (const RWLock::WriterLock &) | |
RWLock::WriterLock & | operator= (const RWLock::WriterLock &) |
int | lock () |
int | trylock () |
int | unlock () |
WriterLock (RWLock &rw_lock_) | |
WriterLock (RWLock &rw_lock_, Locked tag) | |
WriterLock () | |
~WriterLock () |
A scoped locking class for exception safe RWLock write locking.
Cgu::Thread::RWLock::WriterLock::WriterLock | ( | const RWLock::WriterLock & | ) |
This class cannot be copied. The copy constructor is deleted.
Cgu::Thread::RWLock::WriterLock::WriterLock | ( | RWLock & | rw_lock_ | ) | [inline] |
This constructor locks for writing the read-write lock passed to it. It is not a cancellation point. It does not throw.
rw_lock_ | The read-write lock to be locked for writing. |
This constructor takes a read-write lock already locked for writing (say as a result of RWLock::writer_trylock()), and takes ownership of it. It is not a cancellation point. It does not throw.
rw_lock_ | The read-write lock to be managed for writing by this object. |
tag | Pass the Cgu::Thread::locked enum tag to this parameter. |
Cgu::Thread::RWLock::WriterLock::WriterLock | ( | ) |
This class requires initialisation with a RWLock. The default constructor is deleted.
Cgu::Thread::RWLock::WriterLock::~WriterLock | ( | ) | [inline] |
The destructor unlocks the owned read-write lock. It is not a cancellation point. It does not throw.
int Cgu::Thread::RWLock::WriterLock::lock | ( | ) | [inline] |
Calls RWLock::writer_lock(), and so locks the read-write lock for writing and reacquires ownership. It blocks if the read-write lock is already locked for reading or writing until it becomes free. This method should normally only be called if a previous call has been made to RWLock::WriterLock::unlock() (that is, where the thread owning the RWLock::WriterLock object has temporarily allowed another thread to take the read-write lock concerned for reading or writing). It is not a cancellation point. It does not throw.
RWLock::WriterLock& Cgu::Thread::RWLock::WriterLock::operator= | ( | const RWLock::WriterLock & | ) |
This class cannot be copied. The assignment operator is deleted.
int Cgu::Thread::RWLock::WriterLock::trylock | ( | ) | [inline] |
Calls RWLock::writer_trylock(), and so tries to lock the read-write lock for writing and reacquire ownership, but returns immediately with value EBUSY if it is already locked for reading or writing. This method should normally only be called if a previous call has been made to RWLock::WriterLock::unlock() (that is, where the thread owning the RWLock::WriterLock object has temporarily allowed another thread to take the read-write lock concerned for reading or writing). It is not a cancellation point. It does not throw.
int Cgu::Thread::RWLock::WriterLock::unlock | ( | ) | [inline] |
Calls RWLock::unlock(), and so unlocks a locked read-write lock owned by the calling thread for writing and relinquishes ownership (so temporarily allowing another thread to take the read-write lock). This method should normally only be called if it is to be followed by a call to RWLock::WriterLock::lock() or a successful call to RWLock::WriterLock::trylock() before the RWLock::WriterLock object concerned goes out of scope (otherwise RWLock::WriterLock's destructor will attempt to unlock an already unlocked read-write lock or a read-write lock of which another thread has by then taken ownership - RWLock::WriterLock objects do not maintain state). See RWLock::WriterTrackLock::unlock() for a safe version of this method. It is not a cancellation point. It does not throw.