![]() |
mutable
A Database System for Research and Fast Prototyping
|
This is a helper class that helps managing reader and writer locks claimed from reader_writer_mutex
.
More...
#include <reader_writer_lock.hpp>
Public Member Functions | |
reader_writer_lock (reader_writer_mutex &rw_mutex) | |
reader_writer_lock (const reader_writer_lock &)=delete | |
reader_writer_lock (reader_writer_lock &&other) | |
~reader_writer_lock () | |
reader_writer_lock & | operator= (reader_writer_lock &&other)=default |
bool | owns_read_lock () const |
bool | owns_write_lock () const |
void | lock_read () |
Acquire a read lock. | |
void | lock_write () |
Acquire the write lock. | |
bool | upgrade () |
Tries to upgrade a held read lock to the write lock. | |
void | unlock () |
Private Types | |
enum | { LOCK_NONE , LOCK_READ , LOCK_WRITE } |
Private Attributes | |
std::reference_wrapper< reader_writer_mutex > | rw_mutex_ |
enum m::reader_writer_lock:: { ... } | LOCK_NONE |
This is a helper class that helps managing reader and writer locks claimed from reader_writer_mutex
.
Its main purpose is to automatically unlock on destruction.
Definition at line 241 of file reader_writer_lock.hpp.
|
private |
Enumerator | |
---|---|
LOCK_NONE | holds no lock |
LOCK_READ | holds a read (shared) lock |
LOCK_WRITE | holds a write (exclusive) lock |
Definition at line 245 of file reader_writer_lock.hpp.
|
inlineexplicit |
Definition at line 252 of file reader_writer_lock.hpp.
|
delete |
|
inline |
Definition at line 254 of file reader_writer_lock.hpp.
|
inline |
Definition at line 259 of file reader_writer_lock.hpp.
|
inline |
Acquire a read lock.
This call blocks the calling thread until a read lock was acquired.
Definition at line 270 of file reader_writer_lock.hpp.
References LOCK_READ, and rw_mutex_.
Referenced by m::PODPool< T, Hash, KeyEqual, Copy, ThreadSafe >::operator()(), and m::Pool< T, Hash, KeyEqual, ThreadSafe >::operator()().
|
inline |
Acquire the write lock.
This call blocks the calling thread until the write lock was acquired.
Definition at line 276 of file reader_writer_lock.hpp.
References LOCK_WRITE, and rw_mutex_.
|
default |
|
inline |
Definition at line 266 of file reader_writer_lock.hpp.
References LOCK_READ.
|
inline |
Definition at line 267 of file reader_writer_lock.hpp.
References LOCK_WRITE.
|
inline |
Definition at line 301 of file reader_writer_lock.hpp.
References LOCK_NONE, LOCK_READ, LOCK_WRITE, M_insist, M_unreachable, and rw_mutex_.
Referenced by upgrade(), and ~reader_writer_lock().
|
inline |
Tries to upgrade a held read lock to the write lock.
If this call succeeds, it blocks until the write lock was acquired. If this call fails, immediatly unlocks the held read lock to prevent deadlocks and returns.
NOTE: On failure, the held read lock is unlocked to prevent deadlocks.
As a consequence, a reader that wants to upgrade and fails takes no precedence over other waiting readers or writers. Contrary, a reader that succeeds to upgrade takes precedence over other waiting readers.
Definition at line 290 of file reader_writer_lock.hpp.
References LOCK_READ, LOCK_WRITE, M_insist, rw_mutex_, and unlock().
enum { ... } m::reader_writer_lock::LOCK_NONE |
Referenced by unlock(), and ~reader_writer_lock().
|
private |
Definition at line 244 of file reader_writer_lock.hpp.
Referenced by lock_read(), lock_write(), unlock(), and upgrade().