Qx v0.5.8
Qt Extensions Library
|
The ExclusiveAccess template class is a convenience class that simplifies access to resources secured by a mutex. More...
#include <qx/core/qx-exclusiveaccess.h>
Public Member Functions | |
ExclusiveAccess (AccessType *data, Mutex *mutex) noexcept | |
ExclusiveAccess (ExclusiveAccess &&other) noexcept | |
~ExclusiveAccess () | |
AccessType * | access () |
const AccessType * | access () const |
bool | isLocked () const noexcept |
Mutex * | mutex () const |
AccessType & | operator* () |
const AccessType & | operator* () const |
AccessType * | operator-> () |
const AccessType * | operator-> () const |
ExclusiveAccess & | operator= (ExclusiveAccess &&other) noexcept |
void | relock () noexcept |
void | swap (ExclusiveAccess &other) noexcept |
void | unlock () noexcept |
This class is essentially a slightly more capable QMutexLocker and can be used in the same ways; however, it couples access to the data protected by the mutex (in cases where there is, or data can easily be wrapped within, a single resource) along with the automatic locking/unlocking of QMutexLocker.
This can be useful when exclusive access to data needs to be provided by a class/function:
|
inlineexplicitnoexcept |
Constructs an ExclusiveAccess and locks mutex. The mutex will be unlocked when the ExclusiveAccess is destroyed. If mutex is nullptr
, ExclusiveAccess only provides access to data.
|
inlinenoexcept |
Move-constructs and ExclusiveAccess from other. The mutex, data pointer, and state of other is transferred to the newly constructed instance. After the move, other will no longer manage the mutex, nor have a valid data pointer.
|
inline |
Destroys the ExclusiveAccess and unlocks the mutex provided by the constructor if it's still locked.
|
inline |
Returns a pointer to the data the ExclusiveAccess is providing access to.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inlinenoexcept |
Returns true
if this ExclusiveAccess is currently locking its associated mutex; otherwise, returns false
.
|
inline |
Returns the mutex on which the ExclusiveAccess is operating.
|
inline |
Returns a reference to the data the ExclusiveAccess is providing access to.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Provides convenient access to the members of DataType for the accessible data.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inlinenoexcept |
Move-assigns other onto this ExclusiveAccess. If this ExclusiveAccess was holding onto a locked mutex before the assignment, the mutex will be unlocked. The mutex, data pointer, and state of other is then transferred to this QMutexLocker. After the move, other will no longer manage the mutex, nor have a valid data pointer.
|
inlinenoexcept |
Relocks an unlocked ExclusiveAccess.
|
inlinenoexcept |
Swaps the mutex, data pointer, and state of this ExclusiveAccess with other. This operation is very fast and never fails.
|
inlinenoexcept |
Unlocks this ExclusiveAccess. You can use relock() to lock it again. It does not need to be locked when destroyed.