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_--;
105 bool writeEntered()
const {
110 unsigned readers()
const {
124 std::condition_variable gate1_;
129 std::condition_variable gate2_;
virtual ~ReadLockGuard()
Destructor.
ReadLockGuard(ReadWriteMutex &rw_mutex)
Constructor.
void readUnlock()
Unlock read.
virtual ~ReadWriteMutex()
Destructor.
void writeLock()
Lock write.
void readLock()
Lock read.
static const unsigned WRITE_ENTERED
Constants.
static const unsigned MAX_READERS
The maximum number of readers (flag complement so 2^31 - 1).
void writeUnlock()
Unlock write.
ReadWriteMutex()
Constructor.
Write mutex RAII handler.
WriteLockGuard(ReadWriteMutex &rw_mutex)
Constructor.
virtual ~WriteLockGuard()
Destructor.
Defines the logger used by the top-level component of kea-lfc.