libcommonc++  0.7
ReadWriteLock Class Reference

A Read/Write lock – a synchronization primitive that allows multiple threads to coordinate access to a mutable resource. More...

#include <ReadWriteLock.h++>

Public Member Functions

 ReadWriteLock ()
 Construct a new ReadWriteLock. More...
 
 ~ReadWriteLock ()
 Destructor. More...
 
void lockRead ()
 Acquire a read lock, blocking until the lock is acquired. More...
 
bool tryLockRead (timespan_ms_t timeout=0)
 Try to acquire a read lock, returning if the lock could not be acquired within the given amount of time. More...
 
void lockWrite ()
 Acquire a write lock, blocking until the lock is acquired. More...
 
bool tryLockWrite (timespan_ms_t timeout=0)
 Try to acquire a write lock, returning if the lock could not be acquired within the given amount of time. More...
 
void unlock ()
 Release the lock. More...
 

Static Public Member Functions

static bool supportsTimedLocks ()
 Determine if the host system supports timed read/write locks. More...
 

Detailed Description

A Read/Write lock – a synchronization primitive that allows multiple threads to coordinate access to a mutable resource.

Any number of threads can simultaneously hold the read lock as long as no thread holds the write lock. Conversely, a thread can acquire the write lock as long as no threads are holding the read lock.

See also ScopedReadLock and ScopedWriteLock.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ReadWriteLock()

Construct a new ReadWriteLock.

◆ ~ReadWriteLock()

Destructor.

Member Function Documentation

◆ lockRead()

void lockRead ( )

Acquire a read lock, blocking until the lock is acquired.

◆ lockWrite()

void lockWrite ( )

Acquire a write lock, blocking until the lock is acquired.

◆ supportsTimedLocks()

bool supportsTimedLocks ( )
static

Determine if the host system supports timed read/write locks.

◆ tryLockRead()

bool tryLockRead ( timespan_ms_t  timeout = 0)

Try to acquire a read lock, returning if the lock could not be acquired within the given amount of time.

On platforms that do not support timed read/write locks, the method returns immediately if the lock could not be acquired.

Parameters
timeoutThe timeout, in milliseconds.
Returns
true if the lock was acquired, false otherwise.

◆ tryLockWrite()

bool tryLockWrite ( timespan_ms_t  timeout = 0)

Try to acquire a write lock, returning if the lock could not be acquired within the given amount of time.

On platforms that do not support timed read/write locks, the method returns immediately if the lock could not be acquired.

Parameters
timeoutThe timeout, in milliseconds.
Returns
true if the lock was acquired, false otherwise.

◆ unlock()

void unlock ( )

Release the lock.


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