QgsReadWriteLocker class

The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteLocks.

Locking and unlocking a QReadWriteLocks in complex functions and statements or in exception handling code is error-prone and difficult to debug. QgsReadWriteLocker can be used in such situations to ensure that the state of the lock is always well-defined.

QgsReadWriteLocker should be created within a function where a QReadWriteLock needs to be locked. The lock may be locked when QgsReadWriteLocker is created or when changeMode is called. You can unlock and relock the lock with unlock() and changeMode(). If locked, the lock will be unlocked when the QgsReadWriteLocker is destroyed.

Public types

enum Mode { Read, Write, Unlocked }
A QReadWriteLock can be in 3 different modes, read, write or unlocked.

Constructors, destructors, conversion operators

QgsReadWriteLocker(QReadWriteLock& lock, Mode mode)
Create a new QgsReadWriteLocker for lock and initialize in mode.

Public functions

void changeMode(Mode mode)
Change the mode of the lock to mode.
void unlock()
Unlocks the lock.

Enum documentation

enum QgsReadWriteLocker::Mode

A QReadWriteLock can be in 3 different modes, read, write or unlocked.

Enumerators
Read

Lock for read.

Write

Lock for write.

Unlocked

Unlocked.

Function documentation

void QgsReadWriteLocker::changeMode(Mode mode)

Change the mode of the lock to mode.

The lock will be unlocked and relocked as required.

void QgsReadWriteLocker::unlock()

Unlocks the lock.

Equivalent to doing changeMode( QgsReadWriteLocker::Unlock );