4 #include <condition_variable> 33 size_t readers_count_;
34 std::atomic<bool> writing_;
37 std::condition_variable read_cv_;
38 std::condition_variable write_cv_;
41 std::mutex readers_count_mtx_;
43 std::mutex write_mtx_;
70 std::unique_lock<std::mutex> uk((std::mutex&)read_mtx_);
72 while (writing_ ==
true)
73 ((std::condition_variable&)read_cv_).wait(uk);
76 ((std::mutex&)readers_count_mtx_).lock();
77 ((
size_t&)readers_count_)++;
78 ((std::mutex&)readers_count_mtx_).unlock();
92 std::unique_lock<std::mutex> uk((std::mutex&)readers_count_mtx_);
95 if (readers_count_ != 0 && --((
size_t&)readers_count_) == 0)
99 ((std::condition_variable&)read_cv_).notify_all();
100 ((std::condition_variable&)write_cv_).notify_all();
119 std::unique_lock<std::mutex> uk(write_mtx_);
121 while (writing_ ==
true || readers_count_ > 0)
134 read_cv_.notify_all();
135 write_cv_.notify_all();
141 #include <samchon/library/UniqueReadLock.hpp> 142 #include <samchon/library/UniqueWriteLock.hpp> 144 #include <samchon/library/SharedReadLock.hpp> 145 #include <samchon/library/SharedWriteLock.hpp> void readUnlock() const
Unlock of read.
void readLock() const
Lock on read.
void writeLock()
Lock on writing.
RWMutex()
Default Constructor.
void writeUnlock()
Unlock on writing.