QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsreadwritelocker.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsreadwritelocker.cpp
3  -------------------------
4  begin : September 2018
5  copyright : (C) 2018 by Matthias Kuhn
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsreadwritelocker.h"
19 
21  : mLock( lock )
22  , mMode( mode )
23 {
24  if ( mode == Read )
25  mLock.lockForRead();
26  else if ( mode == Write )
27  mLock.lockForWrite();
28 }
29 
31 {
32  if ( mode == mMode )
33  return;
34 
35  unlock();
36 
37  mMode = mode;
38 
39  if ( mMode == Read )
40  mLock.lockForRead();
41  else if ( mMode == Write )
42  mLock.lockForWrite();
43 }
44 
46 {
47  if ( mMode != Unlocked )
48  mLock.unlock();
49 
50  mMode = Unlocked;
51 }
52 
54 {
55  unlock();
56 }
Mode
A QReadWriteLock can be in 3 different modes, read, write or unlocked.
QgsReadWriteLocker(QReadWriteLock &lock, Mode mode)
Create a new QgsReadWriteLocker for lock and initialize in mode.
void unlock()
Unlocks the lock.
void changeMode(Mode mode)
Change the mode of the lock to mode.