c++-gtk-utils
Public Member Functions | List of all members
Cgu::Thread::RWLock::WriterLock Class Reference

A scoped locking class for exception safe RWLock write locking. More...

#include <c++-gtk-utils/rw_lock.h>

Public Member Functions

int lock ()
 
int trylock ()
 
int unlock ()
 
 WriterLock (RWLock &rw_lock_)
 
 WriterLock (RWLock &rw_lock_, Locked tag)
 
 ~WriterLock ()
 

Detailed Description

A scoped locking class for exception safe RWLock write locking.

See also
Thread::RWLock Thread::RWLock::WriterTrackLock Thread::RWLock::ReaderLock Thread::RWLock::ReaderTrackLock Thread::Thread

Constructor & Destructor Documentation

◆ WriterLock() [1/2]

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.

Parameters
rw_lock_The read-write lock to be locked for writing.

Since 1.2.1

◆ WriterLock() [2/2]

Cgu::Thread::RWLock::WriterLock::WriterLock ( RWLock rw_lock_,
Locked  tag 
)
inline

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.

Parameters
rw_lock_The read-write lock to be managed for writing by this object.
tagPass the Cgu::Thread::locked enum tag to this parameter.

Since 1.2.1

◆ ~WriterLock()

Cgu::Thread::RWLock::WriterLock::~WriterLock ( )
inline

The destructor unlocks the owned read-write lock. It is not a cancellation point. It does not throw.

Since 1.2.1

Member Function Documentation

◆ lock()

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.

Returns
0 if successful, otherwise the pthread read-write lock error number.
Note
With this library implementation, the only pthread error number which could be returned by this method is EDEADLK, which it would do if the default pthread reader lock behaviour happens to return that error rather than deadlock where the thread calling this method already holds a read lock or write lock on the particular read-write lock in question. Most default implementations do not do this (they just deadlock) and hence the return value is usually not worth checking for except during debugging.
See also
RWLock::WriterTrackLock

Since 1.2.1

◆ trylock()

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.

Returns
0 if successful, otherwise EBUSY.
Note
With this library implementation, the only pthread error number which could be returned by this method is EBUSY.
See also
RWLock::WriterTrackLock

Since 1.2.1

◆ unlock()

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.

Returns
0 if successful, otherwise the pthread read-write lock error number.
Note
With this library implementation, the only pthread error number which could be returned by this method is EPERM because the calling thread does hold a lock on the particular read-write lock in question (however POSIX does not require that return value in that case and hence the return value is usually not worth checking for except during debugging).
See also
RWLock::WriterTrackLock

Since 1.2.1


The documentation for this class was generated from the following file: