![]() |
mutable
A Database System for Research and Fast Prototyping
|
NOTE: This class is not thread-safe. More...
#include <reader_writer_lock.hpp>
Public Member Functions | |
uint16_t | readers_waiting () const |
uint16_t | readers_active () const |
uint16_t | writers_waiting () const |
bool | writer_active () const |
bool | reader_wants_upgrade () const |
void | request_read_lock () |
Inform others that we want to acquire a read lock. | |
void | request_write_lock () |
Inform others that we want to acquire the write lock. | |
bool | try_request_upgrade () |
Try to request an upgrade. | |
bool | can_acquire_read_lock () const |
The mutex is in a state where a reader can acquire a reader (shared) lock. | |
bool | can_acquire_write_lock () const |
The mutex is in a state where a writer can acquire a write (exclusive) lock. | |
bool | can_upgrade_lock () const |
The mutex is in a state where a reader can claim the write (exclusive) lock. | |
void | acquire_read_lock () |
Acquires a previously requested read lock. | |
void | acquire_write_lock () |
void | release_read_lock () |
Releases a previously acquired read lock. | |
void | release_write_lock () |
void | upgrade_lock () |
Upgrades an already held read lock to a write lock, after previously requesting to upgrade. | |
Private Attributes | |
uint16_t | readers_waiting_ {0} |
The number of readers waiting to acquire a read lock. | |
uint16_t | writers_waiting_ {0} |
The number of writers waiting to acquire the singular write lock. | |
uint16_t | readers_active_ {0} |
The number of currently active readers, i.e. | |
bool | writer_active_ {false} |
As there can be at most one active writer, we track this information with a bool . | |
bool | reader_wants_upgrade_ {false} |
Whether a single reader wants to upgrade to a writer. | |
NOTE: This class is not thread-safe.
It is the duty of the user to guard accesses to instances of this class.
Definition at line 18 of file reader_writer_lock.hpp.
|
inline |
Acquires a previously requested read lock.
Definition at line 72 of file reader_writer_lock.hpp.
References can_acquire_read_lock(), M_insist, readers_active_, readers_waiting(), and readers_waiting_.
Referenced by m::reader_writer_mutex::lock_read(), and m::reader_writer_mutex::try_lock_read().
|
inline |
Definition at line 79 of file reader_writer_lock.hpp.
References can_acquire_write_lock(), M_insist, writer_active_, writers_waiting(), and writers_waiting_.
Referenced by m::reader_writer_mutex::lock_write(), m::reader_writer_mutex::try_lock_write(), and upgrade_lock().
|
inline |
The mutex is in a state where a reader can acquire a reader (shared) lock.
Definition at line 59 of file reader_writer_lock.hpp.
References m::and, reader_wants_upgrade(), writer_active(), and writers_waiting().
Referenced by acquire_read_lock(), m::reader_writer_mutex::lock_read(), and m::reader_writer_mutex::try_lock_read().
|
inline |
The mutex is in a state where a writer can acquire a write (exclusive) lock.
Definition at line 63 of file reader_writer_lock.hpp.
References m::and, readers_active(), and writer_active().
Referenced by acquire_write_lock(), m::reader_writer_mutex::lock_write(), and m::reader_writer_mutex::try_lock_write().
|
inline |
The mutex is in a state where a reader can claim the write (exclusive) lock.
Definition at line 65 of file reader_writer_lock.hpp.
References m::and, M_insist, reader_wants_upgrade(), readers_active(), writer_active(), and writers_waiting().
Referenced by m::reader_writer_mutex::upgrade(), and upgrade_lock().
|
inline |
Definition at line 38 of file reader_writer_lock.hpp.
References reader_wants_upgrade_.
Referenced by can_acquire_read_lock(), can_upgrade_lock(), try_request_upgrade(), m::reader_writer_mutex::unlock_read(), and m::reader_writer_mutex::upgrade().
|
inline |
Definition at line 35 of file reader_writer_lock.hpp.
References readers_active_.
Referenced by can_acquire_write_lock(), can_upgrade_lock(), release_read_lock(), release_write_lock(), m::reader_writer_mutex::unlock_read(), m::reader_writer_mutex::unlock_write(), and upgrade_lock().
|
inline |
Definition at line 34 of file reader_writer_lock.hpp.
References readers_waiting_.
Referenced by acquire_read_lock(), and m::reader_writer_mutex::unlock_write().
|
inline |
Releases a previously acquired read lock.
Definition at line 87 of file reader_writer_lock.hpp.
References M_insist, readers_active(), readers_active_, and writer_active().
Referenced by m::reader_writer_mutex::unlock_read(), and upgrade_lock().
|
inline |
Definition at line 94 of file reader_writer_lock.hpp.
References M_insist, readers_active(), writer_active(), and writer_active_.
Referenced by m::reader_writer_mutex::unlock_write().
|
inline |
Inform others that we want to acquire a read lock.
Definition at line 41 of file reader_writer_lock.hpp.
References readers_waiting_.
Referenced by m::reader_writer_mutex::lock_read(), and m::reader_writer_mutex::try_lock_read().
|
inline |
Inform others that we want to acquire the write lock.
Definition at line 43 of file reader_writer_lock.hpp.
References writers_waiting_.
Referenced by m::reader_writer_mutex::lock_write(), m::reader_writer_mutex::try_lock_write(), and try_request_upgrade().
|
inline |
Try to request an upgrade.
On success, inform others that we want to upgrade our held read lock to the write lock. When request succeeds, upgrading afterwards is guaranteed to terminate eventually.
true
on success, false
otherwise Definition at line 51 of file reader_writer_lock.hpp.
References reader_wants_upgrade(), reader_wants_upgrade_, and request_write_lock().
Referenced by m::reader_writer_mutex::upgrade().
|
inline |
Upgrades an already held read lock to a write lock, after previously requesting to upgrade.
Definition at line 101 of file reader_writer_lock.hpp.
References acquire_write_lock(), can_upgrade_lock(), M_insist, reader_wants_upgrade_, readers_active(), and release_read_lock().
Referenced by m::reader_writer_mutex::upgrade().
|
inline |
Definition at line 37 of file reader_writer_lock.hpp.
References writer_active_.
Referenced by can_acquire_read_lock(), can_acquire_write_lock(), can_upgrade_lock(), release_read_lock(), and release_write_lock().
|
inline |
Definition at line 36 of file reader_writer_lock.hpp.
References writers_waiting_.
Referenced by acquire_write_lock(), can_acquire_read_lock(), can_upgrade_lock(), m::reader_writer_mutex::unlock_read(), and m::reader_writer_mutex::unlock_write().
|
private |
Whether a single reader wants to upgrade to a writer.
Definition at line 31 of file reader_writer_lock.hpp.
Referenced by reader_wants_upgrade(), try_request_upgrade(), and upgrade_lock().
|
private |
The number of currently active readers, i.e.
the number of readers that successfully claimed and are now holding a read lock.
Definition at line 26 of file reader_writer_lock.hpp.
Referenced by acquire_read_lock(), readers_active(), and release_read_lock().
|
private |
The number of readers waiting to acquire a read lock.
Definition at line 21 of file reader_writer_lock.hpp.
Referenced by acquire_read_lock(), readers_waiting(), and request_read_lock().
|
private |
As there can be at most one active writer, we track this information with a bool
.
Definition at line 28 of file reader_writer_lock.hpp.
Referenced by acquire_write_lock(), release_write_lock(), and writer_active().
|
private |
The number of writers waiting to acquire the singular write lock.
Definition at line 23 of file reader_writer_lock.hpp.
Referenced by acquire_write_lock(), request_write_lock(), and writers_waiting().