CoopSync for TBB 0.1.0
Cooperative synchronization primitives for TBB resumable tasks
Loading...
Searching...
No Matches
coopsync_tbb::shared_mutex::scoped_lock Class Reference

RAII wrapper for mutex that acquires the mutex on construction and releases it on destruction. More...

#include <coopsync_tbb/shared_mutex.hpp>

Public Member Functions

 scoped_lock ()
 Constructs a scoped_lock without acquiring a mutex.
 scoped_lock (shared_mutex &m, bool write=true)
 Constructs a scoped_lock and acquires the given mutex.
 ~scoped_lock ()
 Destroys the scoped_lock and releases the mutex.
 scoped_lock (const scoped_lock &)=delete
 scoped_lock is not copy-constructible.
scoped_lock & operator= (const scoped_lock &)=delete
 scoped_lock is not copy-assignable.
 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.
bool try_acquire (shared_mutex &m, bool write=true)
 Attempts to acquire the mutex without blocking.
void release ()
 Releases the mutex. Does nothing if no mutex was previously acquired.
bool upgrade_to_writer ()
 Changes a writer lock to a reader lock.
bool downgrade_to_reader ()
 Changes a reader lock to a writer lock.

Detailed Description

RAII wrapper for mutex that acquires the mutex on construction and releases it on destruction.

Constructor & Destructor Documentation

◆ scoped_lock()

coopsync_tbb::shared_mutex::scoped_lock::scoped_lock ( shared_mutex & m,
bool write = true )
explicit

Constructs a scoped_lock and acquires the given mutex.

Parameters
mThe mutex to acquire.
writeIf true, acquires the mutex in exclusive (writer) mode. If false, acquires the mutex in shared (reader) mode.

Member Function Documentation

◆ acquire()

void coopsync_tbb::shared_mutex::scoped_lock::acquire ( shared_mutex & m,
bool write = true )

Acquires the mutex.

Parameters
mMutex to acquire.
writeIf true, acquires the mutex in exclusive (writer) mode. If false, acquires the mutex in shared (reader) mode.
Exceptions
std::system_errorif another mutex is already acquired.

◆ downgrade_to_reader()

bool coopsync_tbb::shared_mutex::scoped_lock::downgrade_to_reader ( )

Changes a reader lock to a writer lock.

Returns
false if the lock was released and reacquired. Otherwise, return true.
Exceptions
std::system_errorif no mutex was previously acquired.

◆ try_acquire()

bool coopsync_tbb::shared_mutex::scoped_lock::try_acquire ( shared_mutex & m,
bool write = true )
nodiscard

Attempts to acquire the mutex without blocking.

Parameters
mMutex to acquire.
writeIf true, attempts to acquire the mutex in exclusive (writer) mode. If false, attempts to acquire the mutex in shared (reader) mode.
Returns
true if the mutex was successfully acquired, false otherwise.
Exceptions
std::system_errorif another mutex is already acquired.

◆ upgrade_to_writer()

bool coopsync_tbb::shared_mutex::scoped_lock::upgrade_to_writer ( )

Changes a writer lock to a reader lock.

Returns
false if the lock was released and reacquired. Otherwise, return true.
Exceptions
std::system_errorif no mutex was previously acquired.

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