CopperSpice API  1.7.4
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)

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

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

Method Documentation

void QRecursiveMutexLocker::lock ( )

Locks the mutex passed in the constructor.

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

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

void QRecursiveMutexLocker::relock ( )

Equivalent to calling lock().

void QRecursiveMutexLocker::unlock ( )

Unlocks this mutex passed in the constructor.

See also
lock(), relock()