9#include "coopsync_tbb/detail/macros.hpp"
10#include "coopsync_tbb/detail/wait_queue.hpp"
54 COOPSYNC_TBB_NODISCARD
bool try_lock() noexcept;
98 static constexpr
int k_transition =
100 static constexpr
int k_writer_locked = -1;
102 std::atomic<
int> m_state = {0};
104 detail::wait_queue m_writer_waiters;
105 detail::wait_queue m_reader_waiters;
170 bool m_is_writer_lock;
RAII wrapper for mutex that acquires the mutex on construction and releases it on destruction.
Definition shared_mutex.hpp:110
scoped_lock(const scoped_lock &)=delete
scoped_lock is not copy-constructible.
void release()
Releases the mutex. Does nothing if no mutex was previously acquired.
scoped_lock & operator=(const scoped_lock &)=delete
scoped_lock is not copy-assignable.
bool try_acquire(shared_mutex &m, bool write=true)
Attempts to acquire the mutex without blocking.
bool downgrade_to_reader()
Changes a reader lock to a writer lock.
~scoped_lock()
Destroys the scoped_lock and releases the mutex.
scoped_lock()
Constructs a scoped_lock without acquiring a mutex.
scoped_lock(scoped_lock &&)=delete
scoped_lock is not move-constructible.
scoped_lock & operator=(scoped_lock &&)=delete
scoped_lock is not move-assignable.
void acquire(shared_mutex &m, bool write=true)
Acquires the mutex.
scoped_lock(shared_mutex &m, bool write=true)
Constructs a scoped_lock and acquires the given mutex.
bool upgrade_to_writer()
Changes a writer lock to a reader lock.
A shared mutex that can be used to synchronize access to shared resources. The mutex can be acquired ...
Definition shared_mutex.hpp:24
shared_mutex & operator=(const shared_mutex &)=delete
The shared_mutex is not copy-assignable.
void lock_shared()
Acquires the shared_mutex in a shared mode, suspending the calling task if necessary until the shared...
shared_mutex(const shared_mutex &)=delete
The shared_mutex is not copy-constructible.
void unlock()
Releases the shared_mutex. If there are tasks suspended on the shared_mutex, either one of the exclus...
shared_mutex & operator=(shared_mutex &&)=delete
shared_mutex is not move-assignable.
bool try_lock_shared() noexcept
Attempts to acquire the shared_mutex in a shared mode without suspending.
static constexpr bool is_rw_mutex
The shared_mutex is a reader-writer (shared) mutex.
Definition shared_mutex.hpp:90
void unlock_shared()
Releases the shared_mutex from a shared mode. If there are tasks suspended on the shared_mutex,...
bool try_lock() noexcept
Attempts to acquire the shared_mutex without suspending.
static constexpr bool is_recursive_mutex
The shared_mutex is not recursive.
Definition shared_mutex.hpp:92
~shared_mutex()
Destroys the shared_mutex.
void lock()
Acquires the shared_mutex, suspending the calling task if necessary until the shared_mutex becomes av...
shared_mutex()=default
Constructs a new shared_mutex. The shared_mutex is initially unlocked.
shared_mutex(shared_mutex &&)=delete
The shared_mutex is not move-constructible.
static constexpr bool is_fair_mutex
The shared_mutex does not provide any fairness guarantees.
Definition shared_mutex.hpp:94
Main namespace of the library, containing all public APIs.
Definition wait_for.hpp:11
shared_mutex rw_mutex
Alias for shared_mutex, following the TBB convention of naming reader-writer mutexes.
Definition shared_mutex.hpp:175