TDME2  1.9.200
ReadWriteLock.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <tdme/tdme.h>
6 
7 #include <shared_mutex>
8 #include <string>
9 
10 using std::shared_mutex;
11 using std::string;
12 
13 /**
14  * Implementation for read/write lock
15  * @author Andreas Drewke
16  */
18 public:
19  // forbid class copy
21 
22  /**
23  * @brief Public constructor
24  * @param name name
25  */
26  inline ReadWriteLock(const string& name): name(name) {}
27 
28  /**
29  * @brief Destroys the read write lock
30  */
31  inline ~ReadWriteLock() {}
32 
33  /**
34  * @brief Locks for reading / shared lock
35  */
36  inline void readLock() {
37  stlSharedMutex.lock_shared();
38  }
39 
40  /**
41  * @brief Locks for writing / exclusive lock
42  */
43  inline void writeLock() {
44  stlSharedMutex.lock();
45  }
46 
47  /**
48  * @brief Unlocks this read write lock
49  */
50  inline void unlock() {
51  stlSharedMutex.unlock();
52  }
53 
54 private:
55  string name;
56  shared_mutex stlSharedMutex;
57 };
Implementation for read/write lock.
Definition: ReadWriteLock.h:17
void writeLock()
Locks for writing / exclusive lock.
Definition: ReadWriteLock.h:43
void unlock()
Unlocks this read write lock.
Definition: ReadWriteLock.h:50
~ReadWriteLock()
Destroys the read write lock.
Definition: ReadWriteLock.h:31
void readLock()
Locks for reading / shared lock.
Definition: ReadWriteLock.h:36
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6