mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
m::detail::reader_writer_mutex_internal Class Reference

NOTE: This class is not thread-safe. More...

#include <reader_writer_lock.hpp>

Collaboration diagram for m::detail::reader_writer_mutex_internal:
[legend]

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.
 

Detailed Description

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.

Member Function Documentation

◆ acquire_read_lock()

void m::detail::reader_writer_mutex_internal::acquire_read_lock ( )
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().

◆ acquire_write_lock()

void m::detail::reader_writer_mutex_internal::acquire_write_lock ( )
inline

◆ can_acquire_read_lock()

bool m::detail::reader_writer_mutex_internal::can_acquire_read_lock ( ) const
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().

◆ can_acquire_write_lock()

bool m::detail::reader_writer_mutex_internal::can_acquire_write_lock ( ) const
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().

◆ can_upgrade_lock()

bool m::detail::reader_writer_mutex_internal::can_upgrade_lock ( ) const
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().

◆ reader_wants_upgrade()

bool m::detail::reader_writer_mutex_internal::reader_wants_upgrade ( ) const
inline

◆ readers_active()

uint16_t m::detail::reader_writer_mutex_internal::readers_active ( ) const
inline

◆ readers_waiting()

uint16_t m::detail::reader_writer_mutex_internal::readers_waiting ( ) const
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().

◆ release_read_lock()

void m::detail::reader_writer_mutex_internal::release_read_lock ( )
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().

◆ release_write_lock()

void m::detail::reader_writer_mutex_internal::release_write_lock ( )
inline

◆ request_read_lock()

void m::detail::reader_writer_mutex_internal::request_read_lock ( )
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().

◆ request_write_lock()

void m::detail::reader_writer_mutex_internal::request_write_lock ( )
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().

◆ try_request_upgrade()

bool m::detail::reader_writer_mutex_internal::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.

Returns
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().

◆ upgrade_lock()

void m::detail::reader_writer_mutex_internal::upgrade_lock ( )
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().

◆ writer_active()

bool m::detail::reader_writer_mutex_internal::writer_active ( ) const
inline

◆ writers_waiting()

uint16_t m::detail::reader_writer_mutex_internal::writers_waiting ( ) const
inline

Field Documentation

◆ reader_wants_upgrade_

bool m::detail::reader_writer_mutex_internal::reader_wants_upgrade_ {false}
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().

◆ readers_active_

uint16_t m::detail::reader_writer_mutex_internal::readers_active_ {0}
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().

◆ readers_waiting_

uint16_t m::detail::reader_writer_mutex_internal::readers_waiting_ {0}
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().

◆ writer_active_

bool m::detail::reader_writer_mutex_internal::writer_active_ {false}
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().

◆ writers_waiting_

uint16_t m::detail::reader_writer_mutex_internal::writers_waiting_ {0}
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().


The documentation for this class was generated from the following file: