RAVENNAKIT
Loading...
Searching...
No Matches
rav::AtomicRwLock Class Reference

A lock-free (and sometimes wait-free) reader writer lock. More...

#include <atomic_rw_lock.hpp>

Classes

struct  Exclusive
 Exclusive unlock function. More...
struct  Shared
 Shared unlock function. More...
struct  AccessGuard
 Guards access to a critical region. More...

Public Member Functions

AccessGuard< Exclusive > lock_exclusive ()
 Attempts to acquire an exclusive lock, spinning util it succeeds, or until the loop upper bounds is reached.
AccessGuard< Exclusive > try_lock_exclusive ()
 Attempts to acquire an exclusive lock.
AccessGuard< Shared > lock_shared ()
 Attempts to acquire a shared lock, spinning util it succeeds, or until the loop upper bounds is reached.
AccessGuard< Shared > try_lock_shared ()
 Attempts to acquire a shared lock.
bool is_locked_shared () const
bool is_locked_exclusively () const
bool is_locked () const

Static Public Attributes

static constexpr size_t k_loop_upper_bound = 1'000'000
 The max number of tries before giving up (preventing runaway code).
static constexpr uint32_t k_yield_threshold = 10
 The number of iterations after which a function will start yielding.
static constexpr uint32_t k_sleep_threshold = 10'000
 The number of iterations after which a function will start sleeping.

Detailed Description

A lock-free (and sometimes wait-free) reader writer lock.

Definition at line 37 of file atomic_rw_lock.hpp.

Member Function Documentation

◆ is_locked()

bool rav::AtomicRwLock::is_locked ( ) const
inlinenodiscard
Returns
True if locked shared or exclusively. This is a relaxed check and cannot be used to draw any conclusions.

Definition at line 204 of file atomic_rw_lock.hpp.

◆ is_locked_exclusively()

bool rav::AtomicRwLock::is_locked_exclusively ( ) const
inlinenodiscard
Returns
True if locked exclusively. This is a relaxed check and cannot be used to draw any conclusions.

Definition at line 197 of file atomic_rw_lock.hpp.

◆ is_locked_shared()

bool rav::AtomicRwLock::is_locked_shared ( ) const
inlinenodiscard
Returns
True if shared locked. This is a relaxed check and cannot be used to draw any conclusions.

Definition at line 190 of file atomic_rw_lock.hpp.

◆ lock_exclusive()

AccessGuard< Exclusive > rav::AtomicRwLock::lock_exclusive ( )
inlinenodiscard

Attempts to acquire an exclusive lock, spinning util it succeeds, or until the loop upper bounds is reached.

Thread safe: yes Wait-free: no

Returns
A guard which holds on to the lock as long as it's alive. Check for validity before using.

Definition at line 100 of file atomic_rw_lock.hpp.

◆ lock_shared()

AccessGuard< Shared > rav::AtomicRwLock::lock_shared ( )
inlinenodiscard

Attempts to acquire a shared lock, spinning util it succeeds, or until the loop upper bounds is reached.

Thread safe: yes Wait-free: no

Returns
A guard which holds on to the lock as long as it's alive. Check for validity before using.

Definition at line 148 of file atomic_rw_lock.hpp.

◆ try_lock_exclusive()

AccessGuard< Exclusive > rav::AtomicRwLock::try_lock_exclusive ( )
inlinenodiscard

Attempts to acquire an exclusive lock.

Note: this call can fail if a reader is trying to get access at the same time. Thread safe: yes Wait-free: yes

Returns
A guard which holds on to the lock as long as it's alive. Check for validity before using.

Definition at line 134 of file atomic_rw_lock.hpp.

◆ try_lock_shared()

AccessGuard< Shared > rav::AtomicRwLock::try_lock_shared ( )
inlinenodiscard

Attempts to acquire a shared lock.

This will always succeed when there is no exclusive lock. This call will always succeed if there are no writers (waiting). Thread safe: yes Wait-free: yes

Returns
A guard which holds on to the lock as long as it's alive. Check for validity before using.

Definition at line 171 of file atomic_rw_lock.hpp.

Member Data Documentation

◆ k_loop_upper_bound

size_t rav::AtomicRwLock::k_loop_upper_bound = 1'000'000
staticconstexpr

The max number of tries before giving up (preventing runaway code).

Definition at line 40 of file atomic_rw_lock.hpp.

◆ k_sleep_threshold

uint32_t rav::AtomicRwLock::k_sleep_threshold = 10'000
staticconstexpr

The number of iterations after which a function will start sleeping.

Definition at line 46 of file atomic_rw_lock.hpp.

◆ k_yield_threshold

uint32_t rav::AtomicRwLock::k_yield_threshold = 10
staticconstexpr

The number of iterations after which a function will start yielding.

Definition at line 43 of file atomic_rw_lock.hpp.


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