7 #ifndef READWRITE_MUTEX_H
8 #define READWRITE_MUTEX_H
17 #include <boost/noncopyable.hpp>
19 #include <condition_variable>
36 1U << (
sizeof(unsigned) * CHAR_BIT - 1);
50 std::lock_guard<std::mutex> lk(mutex_);
55 std::unique_lock<std::mutex> lk(mutex_);
57 gate1_.wait(lk, [=]() {
return (!writeEntered()); });
60 gate2_.wait(lk, [=]() {
return (readers() == 0); });
67 std::lock_guard<std::mutex> lk(mutex_);
75 std::unique_lock<std::mutex> lk(mutex_);
77 gate1_.wait(lk, [=]() {
return (state_ < MAX_READERS); });
85 std::lock_guard<std::mutex> lk(mutex_);
86 unsigned prev = state_--;
93 if (prev == MAX_READERS) {
105 bool writeEntered()
const {
110 unsigned readers()
const {
111 return (state_ & MAX_READERS);
124 std::condition_variable gate1_;
129 std::condition_variable gate2_;
187 #endif // READWRITE_MUTEX_H
WriteLockGuard(ReadWriteMutex &rw_mutex)
Constructor.
Write mutex RAII handler.
virtual ~ReadLockGuard()
Destructor.
ReadWriteMutex()
Constructor.
static const unsigned MAX_READERS
The maximum number of readers (flag complement so 2^31 - 1).
virtual ~ReadWriteMutex()
Destructor.
static const unsigned WRITE_ENTERED
Constants.
virtual ~WriteLockGuard()
Destructor.
Defines the logger used by the top-level component of kea-dhcp-ddns.
ReadLockGuard(ReadWriteMutex &rw_mutex)
Constructor.
void readUnlock()
Unlock read.
void writeLock()
Lock write.
void readLock()
Lock read.
void writeUnlock()
Unlock write.