QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
Public Types | Public Member Functions | List of all members
QgsReadWriteLocker Class Reference

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

#include <qgsreadwritelocker.h>

Public Types

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

Public Member Functions

 QgsReadWriteLocker (QReadWriteLock &lock, Mode mode)
 Create a new QgsReadWriteLocker for lock and initialize in mode. More...
 
 ~QgsReadWriteLocker ()
 
void changeMode (Mode mode)
 Change the mode of the lock to mode. More...
 
void unlock ()
 Unlocks the lock. More...
 

Detailed Description

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.

Since
QGIS 3.4

Definition at line 40 of file qgsreadwritelocker.h.

Member Enumeration Documentation

◆ Mode

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

Enumerator
Read 

Lock for read.

Write 

Lock for write.

Unlocked 

Unlocked.

Definition at line 47 of file qgsreadwritelocker.h.

Constructor & Destructor Documentation

◆ QgsReadWriteLocker()

QgsReadWriteLocker::QgsReadWriteLocker ( QReadWriteLock &  lock,
QgsReadWriteLocker::Mode  mode 
)

Create a new QgsReadWriteLocker for lock and initialize in mode.

Definition at line 20 of file qgsreadwritelocker.cpp.

◆ ~QgsReadWriteLocker()

QgsReadWriteLocker::~QgsReadWriteLocker ( )

Definition at line 53 of file qgsreadwritelocker.cpp.

Member Function Documentation

◆ changeMode()

void QgsReadWriteLocker::changeMode ( QgsReadWriteLocker::Mode  mode)

Change the mode of the lock to mode.

The lock will be unlocked and relocked as required.

Definition at line 30 of file qgsreadwritelocker.cpp.

◆ unlock()

void QgsReadWriteLocker::unlock ( )

Unlocks the lock.

Equivalent to doing changeMode( QgsReadWriteLocker::Unlock );

Definition at line 45 of file qgsreadwritelocker.cpp.


The documentation for this class was generated from the following files: