CopperSpice API  1.9.1
QRecursiveMutexLocker Class Reference

Simplifies locking and unlocking mutexes. More...

Public Methods

 QRecursiveMutexLocker (QRecursiveMutex *mutex)
 
 ~QRecursiveMutexLocker () = default
 
void lock ()
 
QRecursiveMutexmutex () const
 
void relock ()
 
void unlock ()
 

Detailed Description

The QRecursiveMutexLocker class simplifies locking and unlocking mutexes. Locking and unlocking a QRecursiveMutex manually in complex functions or in exception handling code is error prone and can be difficult to debug. QRecursiveMutexLocker can be used in such situations to ensure the state of the mutex is always well defined.

The mutex will be locked when QRecursiveMutexLocker is created. You can unlock and relock the mutex with unlock() and relock(). If locked, the mutex will be unlocked when the QRecursiveMutexLocker is destroyed.

The QMutexLocker class provides the equivalent functionality for code which does not use a recursive mutex.

See also
QMutex, QMutexLocker, QReadLocker, QRecursiveMutex, QWriteLocker

Constructor & Destructor Documentation

QRecursiveMutexLocker::QRecursiveMutexLocker ( QRecursiveMutex mutex)
inlineexplicit

Constructs a QRecursiveMutexLocker and locks mutex. The mutex will be unlocked when the QRecursiveMutexLocker is destroyed. If mutex is a nullptr QRecursiveMutexLocker does nothing.

QRecursiveMutexLocker::~QRecursiveMutexLocker ( )
default

Destroys the QRecursiveMutexLocker and unlocks the mutex that was locked in the constructor.

Method Documentation

void QRecursiveMutexLocker::lock ( )
inline

Locks the mutex passed in the constructor.

See also
relock(), unlock()
QRecursiveMutex * QRecursiveMutexLocker::mutex ( ) const
inline

Returns a pointer to the mutex which was locked in the constructor.

void QRecursiveMutexLocker::relock ( )
inline

Equivalent to calling lock().

void QRecursiveMutexLocker::unlock ( )
inline

Unlocks this mutex passed in the constructor.

See also
lock(), relock()