A readers‐writer lock which allows multiple readers to hold the lock simultaneously or only one writer.

Synopsis

Declared in <folly/fibers/TimedMutex.h>

template<
    bool ReaderPriority,
    typename BatonType>
class TimedRWMutexImpl;

Description

NOTE: When ReaderPriority is set to true then the lock is a reader‐preferred RWLock i.e. readers are given priority when there are both readers and writers waiting to get the lock.

When ReaderPriority is set to false then the lock is a writer‐preferred RWLock i.e. writers are given priority when there are both readers and writers waiting to get the lock. Note that when the lock is in writer‐preferred mode, the readers are not re‐entrant (e.g. if a caller owns a read lock, it can't attempt to acquire the read lock again as it can deadlock.)

Member Functions

Name

Description

TimedRWMutexImpl [constructor]

Constructors

~TimedRWMutexImpl [destructor]

Destroy the mutex.

operator=

Assignment operators

lock

Obtain an exclusive lock. The thread / fiber is blocked until the lock is available.

lock_shared

Lock for shared access. The thread / fiber is blocked until the lock can be acquired.

try_lock

Like lock but doesn't block the thread / fiber if the lock cant be obtained.

try_lock_for

Like lock except the thread / fiber is blocked until a timeout elapses.

try_lock_shared

Like lock_shared but doesn't block the thread / fiber if the lock can't be acquired.

try_lock_shared_for

Like lock_shared except the thread / fiber is blocked until a timeout elapses.

try_lock_shared_until

Like lock_shared except the thread / fiber is blocked until a deadline.

try_lock_until

Like lock except the thread / fiber is blocked until a deadline.

unlock

Release the exclusive lock. The thread / fiber will wake up all readers if there are any. If there are waiting writers then only one of them will be woken up.

unlock_and_lock_shared

Downgrade the lock. The thread / fiber will wake up all readers if there are any.

unlock_shared

Release the shared lock. The thread / fiber will wake up a writer if there is one and if this is the last concurrently‐held read lock to be released.

Created with MrDocs