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

A scoped locking class for exception safe locking of GStaticRecMutex objects. More...

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

Public Member Functions

 GrecmutexLock (const GrecmutexLock &)=delete
 
GrecmutexLockoperator= (const GrecmutexLock &)=delete
 
GStaticRecMutex * get () const
 
 GrecmutexLock (GStaticRecMutex &mutex_)
 
 GrecmutexLock (GStaticRecMutex &mutex_, Locked tag)
 
 GrecmutexLock ()=delete
 
 ~GrecmutexLock ()
 

Detailed Description

A scoped locking class for exception safe locking of GStaticRecMutex objects.

This class is mainly intended for use where the native pthreads implementation does not support recursive mutexes so Cgu::Thread::RecMutex and Cgu::Thread::RecMutex::Lock cannot be used.

It should be noted that this class is for use with GStaticRecMutex objects, and not the GRecMutex objects available in glib from glib version 2.32. If glib >= 2.32 is installed, it can be assumed that native recursive mutexes and so Cgu::Thread::RecMutex are available, as glib >= 2.32 also uses native recursive mutexes.

Constructor & Destructor Documentation

◆ GrecmutexLock() [1/4]

Cgu::Thread::GrecmutexLock::GrecmutexLock ( const GrecmutexLock )
delete

This class cannot be copied. The copy constructor is deleted.

◆ GrecmutexLock() [2/4]

Cgu::Thread::GrecmutexLock::GrecmutexLock ( GStaticRecMutex &  mutex_)

This constructor locks the mutex and acquires ownership, and blocks if it is already locked until it becomes free, unless the constructing thread already holds the lock, in which case it increments the lock count and returns immediately. It is not a cancellation point. It does not throw.

Parameters
mutex_The mutex to be locked.

◆ GrecmutexLock() [3/4]

Cgu::Thread::GrecmutexLock::GrecmutexLock ( GStaticRecMutex &  mutex_,
Locked  tag 
)
inline

This constructor takes an already locked mutex (say as a result of g_static_rec_mutex_trylock()), and takes ownership of it. It is not a cancellation point. It does not throw.

Parameters
mutex_The mutex to be managed by this object.
tagPass the Cgu::Thread::locked enum tag to this parameter.

◆ GrecmutexLock() [4/4]

Cgu::Thread::GrecmutexLock::GrecmutexLock ( )
delete

This class requires initialisation with a GStaticRecMutex. The default constructor is deleted.

◆ ~GrecmutexLock()

Cgu::Thread::GrecmutexLock::~GrecmutexLock ( )

The destructor unlocks the owned mutex, and either relinquishes ownership (if the mutex has not been recursively locked) or decrements the lock count (if it has). It is not a cancellation point. It does not throw.

Member Function Documentation

◆ get()

GStaticRecMutex* Cgu::Thread::GrecmutexLock::get ( ) const
inline

This method provides access to the GStaticRecMutex object locked by this GrecmutexLock object. It does not throw. It is thread safe.

Returns
A pointer to the GStaticRecMutex object.

◆ operator=()

GrecmutexLock& Cgu::Thread::GrecmutexLock::operator= ( const GrecmutexLock )
delete

This class cannot be copied. The assignment operator is deleted.


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