The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks for read access. 更多...
| 頭: | #include <QReadLocker> |
| qmake: | QT += core |
注意: 此類的所有函數 綫程安全 .
| QReadLocker (QReadWriteLock * lock ) | |
| ~QReadLocker () | |
| QReadWriteLock * | readWriteLock () const |
| void | relock () |
| void | unlock () |
The purpose of QReadLocker (and QWriteLocker ) 是簡化 QReadWriteLock locking and unlocking. Locking and unlocking statements or in exception handling code is error-prone and difficult to debug. QReadLocker can be used in such situations to ensure that the state of the lock is always well-defined.
Here's an example that uses QReadLocker to lock and unlock a read-write lock for reading:
QReadWriteLock lock; QByteArray readData() { QReadLocker locker(&lock); ... return data; }
它相當於以下代碼:
QReadWriteLock lock; QByteArray readData() { lock.lockForRead(); ... lock.unlock(); return data; }
The QMutexLocker 文檔編製展示使用鎖定器對象大大簡化編程的範例。
另請參閱 QWriteLocker and QReadWriteLock .
Constructs a QReadLocker and locks
lock
for reading. The lock will be unlocked when the QReadLocker is destroyed. If
lock
is zero, QReadLocker does nothing.
另請參閱 QReadWriteLock::lockForRead ().
銷毀 QReadLocker 並解鎖被傳遞給構造函數的鎖。
另請參閱 QReadWriteLock::unlock ().
返迴指嚮被傳遞給構造函數的讀寫鎖的指針。
重新鎖定被解鎖的鎖。
另請參閱 unlock ().
解鎖關聯此鎖定器的鎖。
另請參閱 QReadWriteLock::unlock ().