libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
ReadWriteLock Class Reference

Reader-writer lock wrapping std::shared_mutex. More...

#include <readwritelock.h>

Classes

class  ReadLocker
 RAII scoped locker for shared (read) access. More...
 
class  WriteLocker
 RAII scoped locker for exclusive (write) access. More...
 

Public Member Functions

 ReadWriteLock ()=default
 Constructs an unlocked ReadWriteLock.
 
 ~ReadWriteLock ()=default
 Destructor.
 
 ReadWriteLock (const ReadWriteLock &)=delete
 
ReadWriteLockoperator= (const ReadWriteLock &)=delete
 
 ReadWriteLock (ReadWriteLock &&)=delete
 
ReadWriteLockoperator= (ReadWriteLock &&)=delete
 
void lockForRead ()
 Acquires a shared (read) lock. Multiple readers may hold this concurrently.
 
void lockForWrite ()
 Acquires an exclusive (write) lock. Blocks until all readers and writers release.
 
void unlock ()
 Releases the currently held lock (shared or exclusive).
 
bool tryLockForRead ()
 Attempts to acquire a shared (read) lock without blocking.
 
bool tryLockForWrite ()
 Attempts to acquire an exclusive (write) lock without blocking.
 

Detailed Description

Reader-writer lock wrapping std::shared_mutex.

Allows multiple concurrent readers or a single exclusive writer. Provides nested RAII ReadLocker and WriteLocker types. Non-copyable and non-movable.

Member Function Documentation

◆ tryLockForRead()

bool ReadWriteLock::tryLockForRead ( )
inline

Attempts to acquire a shared (read) lock without blocking.

Returns
True if the lock was acquired, false otherwise.

◆ tryLockForWrite()

bool ReadWriteLock::tryLockForWrite ( )
inline

Attempts to acquire an exclusive (write) lock without blocking.

Returns
True if the lock was acquired, false otherwise.

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