emilib
Public Member Functions | List of all members
emilib::SlowReadWriteMutex Class Reference

#include <read_write_mutex.hpp>

Public Member Functions

void lock ()
 
bool try_lock ()
 
void unlock ()
 
void lock_shared ()
 
bool try_lock_shared ()
 
void unlock_shared ()
 

Detailed Description

This is a good mutex if reading is slow to save on CPU usage when there is a thread waiting to write. This is a drop-in replacement for C++17's std::shared_mutex. This mutex is NOT recursive!

Member Function Documentation

◆ lock()

void emilib::SlowReadWriteMutex::lock ( )
inline

Locks the mutex for exclusive access (e.g. for a write operation). If another thread has already locked the mutex, a call to lock will block execution until the lock is acquired. If lock is called by a thread that already owns the mutex in any mode (shared or exclusive), the behavior is undefined.

◆ lock_shared()

void emilib::SlowReadWriteMutex::lock_shared ( )
inline

Acquires shared ownership of the mutex (e.g. for a read operation). If another thread is holding the mutex in exclusive ownership, a call to lock_shared will block execution until shared ownership can be acquired.

◆ try_lock()

bool emilib::SlowReadWriteMutex::try_lock ( )
inline

Tries to lock the mutex. Returns immediately. On successful lock acquisition returns true, otherwise returns false. This function is allowed to fail spuriously and return false even if the mutex is not currently locked by any other thread. If try_lock is called by a thread that already owns the mutex, the behavior is undefined.

◆ try_lock_shared()

bool emilib::SlowReadWriteMutex::try_lock_shared ( )
inline

Tries to lock the mutex in shared mode. Returns immediately. On successful lock acquisition returns true, otherwise returns false. This function is allowed to fail spuriously and return false even if the mutex is not currenly exclusively locked by any other thread.

◆ unlock_shared()

void emilib::SlowReadWriteMutex::unlock_shared ( )
inline

Releases the mutex from shared ownership by the calling thread. The mutex must be locked by the current thread of execution in shared mode, otherwise, the behavior is undefined.


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