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

A scoped locking class for exception safe RWLock write 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
 
 WriterTrackLock (RWLock &rw_lock_)
 
 WriterTrackLock (RWLock &rw_lock_, Locked tag)
 
 WriterTrackLock (RWLock &rw_lock_, DeferLock tag)
 
 ~WriterTrackLock ()
 

Detailed Description

A scoped locking class for exception safe RWLock write locking which tracks the status of its read-write lock..

See also
Thread::RWLock Thread::RWLock::WriterLock Thread::RWLock::ReaderLock Thread::RWLock::ReaderTrackLock Thread::Thread

This class is similar to a RWLock::WriterLock object, except that it tracks whether the read-write lock it manages is locked for writing by the thread creating the RWLock::WriterTrackLock object (provided that, while the RWLock::WriterTrackLock object exists, the thread creating it only accesses the managed read-write lock for write-locking through that object). This enables RWLock::WriterTrackLock::unlock() to be used without it being followed later by a call to RWLock::WriterTrackLock::lock() or a successful call to RWLock::WriterTrackLock::trylock(), and also permits locking to be deferred until after construction of the RWLock::WriterTrackLock object. Note that only one thread may call the methods of any one RWLock::WriterTrackLock object, including causing its destructor to be invoked.

Constructor & Destructor Documentation

Cgu::Thread::RWLock::WriterTrackLock::WriterTrackLock ( 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

Cgu::Thread::RWLock::WriterTrackLock::WriterTrackLock ( 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

Cgu::Thread::RWLock::WriterTrackLock::WriterTrackLock ( RWLock rw_lock_,
DeferLock  tag 
)
inline

This constructor defers locking of the read-write lock for writing until an explicit call to lock() or trylock() is made. 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::defer enum tag to this parameter.

Since 1.2.1

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

The destructor unlocks the read-write lock which is managed for writing if it is owned by this RWLock::WriterTrackLock object. It is not a cancellation point. It does not throw.

Since 1.2.1

Member Function Documentation

bool Cgu::Thread::RWLock::WriterTrackLock::is_owner ( ) const
inline

Indicates whether the read-write lock managed by this RWLock::ReaderTrackLock object is locked for writing by it and so owned by it. It does not throw.

Returns
true if the read-write lock is owned by this object, otherwise false.

Since 1.2.1

int Cgu::Thread::RWLock::WriterTrackLock::lock ( )
inline

Calls RWLock::writer_lock(), and so locks the read-write lock for writing and acquires 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::WriterTrackLock::unlock() or this RWLock::WriterTrackLock object has been constructed with the Thread::defer enum tag. 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.

Since 1.2.1

int Cgu::Thread::RWLock::WriterTrackLock::trylock ( )
inline

Calls RWLock::writer_trylock(), and so tries to lock the read-write lock for writing and acquire 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::WriterTrackLock::unlock() or this RWLock::WriterTrackLock object has been constructed with the Thread::defer enum tag. 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.

Since 1.2.1

int Cgu::Thread::RWLock::WriterTrackLock::unlock ( )
inline

Calls RWLock::unlock(), and so unlocks a locked read-write lock owned by the calling thread for writing and relinquishes ownership. 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.

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).

Since 1.2.1


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