Qt 4.8
|
The QMutexPool class provides a pool of QMutex objects. More...
#include <qmutexpool_p.h>
Public Functions | |
QMutex * | get (const void *address) |
Returns a QMutex from the pool. More... | |
QMutexPool (QMutex::RecursionMode recursionMode=QMutex::NonRecursive, int size=131) | |
Constructs a QMutexPool, reserving space for size QMutexes. More... | |
~QMutexPool () | |
Destructs a QMutexPool. More... | |
Static Public Functions | |
static QMutex * | globalInstanceGet (const void *address) |
Returns a QMutex from the global mutex pool. More... | |
static QMutexPool * | instance () |
Returns the global QMutexPool instance. More... | |
Private Functions | |
QMutex * | createMutex (int index) |
Properties | |
QVarLengthArray< QAtomicPointer< QMutex >, 131 > | mutexes |
QMutex::RecursionMode | recursionMode |
The QMutexPool class provides a pool of QMutex objects.
QMutexPool is a convenience class that provides access to a fixed number of QMutex objects.
Typical use of a QMutexPool is in situations where it is not possible or feasible to use one QMutex for every protected object. The mutex pool will return a mutex based on the address of the object that needs protection.
For example, consider this simple class:
Adding a QMutex member to the Number class does not make sense, because it is so small. However, in order to ensure that access to each Number is protected, you need to use a mutex. In this case, a QMutexPool would be ideal.
Code to calculate the square of a number would then look something like this:
This function will safely calculate the square of a number, since it uses a mutex from a QMutexPool. The mutex is locked and unlocked automatically by the QMutexLocker class. See the QMutexLocker documentation for more details.
Definition at line 64 of file qmutexpool_p.h.
|
explicit |
Constructs a QMutexPool, reserving space for size QMutexes.
All mutexes in the pool are created with recursionMode. By default, all mutexes are non-recursive.
The QMutexes are created when needed, and deleted when the QMutexPool is destructed.
Definition at line 101 of file qmutexpool.cpp.
QMutexPool::~QMutexPool | ( | ) |
Destructs a QMutexPool.
All QMutexes that were created by the pool are deleted.
Definition at line 113 of file qmutexpool.cpp.
|
private |
Definition at line 138 of file qmutexpool.cpp.
|
inline |
Returns a QMutex from the pool.
QMutexPool uses the value address to determine which mutex is returned from the pool.
Definition at line 70 of file qmutexpool_p.h.
Referenced by globalInstanceGet(), and signalSlotLock().
|
static |
Returns a QMutex from the global mutex pool.
Definition at line 150 of file qmutexpool.cpp.
Referenced by QHostInfoAgent::fromName(), QVariantAnimationPrivate::getInterpolator(), ignoreSigPipe(), QSslCertificate::issuerInfo(), q_resolveOpenSslSymbols(), qdbus_loadLibDBus(), resolveUNCLibs(), QSslCertificate::serialNumber(), QSslCertificate::subjectInfo(), QPropertyAnimation::updateState(), and QSslCertificate::version().
|
static |
Returns the global QMutexPool instance.
Definition at line 124 of file qmutexpool.cpp.
Referenced by QThread::initialize(), and QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate().
|
private |
Definition at line 83 of file qmutexpool_p.h.
Referenced by createMutex(), and ~QMutexPool().
|
private |
Definition at line 84 of file qmutexpool_p.h.
Referenced by createMutex().