This class provides a multi‐reader/single‐writer lock mechanism.

Synopsis

Declared in <bslmt_readerwriterlock.h>

class ReaderWriterLock;

Member Functions

Name

Description

ReaderWriterLock [constructor]

Construct a reader/writer lock initialized to an unlocked state.

~ReaderWriterLock [destructor]

Destroy this reader/writer lock.

isLocked

Return true if this reader‐write lock is currently read locked or write locked, and false otherwise.

isLockedRead

Return true if this reader‐write lock is currently read locked, and false otherwise.

isLockedWrite

Return true if this reader‐write lock is currently write locked, and false otherwise.

lockRead

Lock this reader/writer lock for read. If there are no pending or active write locks, the call will return immediately, otherwise it block until all write locks have been released. Use unlock to release the lock.

lockReadReserveWrite

Lock this reader/writer lock for read and reserve a write lock so that a call to upgradeToWriteLock is guaranteed to upgrade atomically. If there are no pending or active write locks, the call will return immediately, otherwise it will block until it all active and pending writes have completed. The lock may then be atomically converted to a write lock by calling upgradeToWriteLock. Use unlock to release the lock.

lockWrite

Lock the reader/writer lock for write. The call will block until all active read locks or active/pending write locks are released. When the reader/writer lock is locked for write, all read/write lock attempts will either fail or block until the lock is released. Use unlock to release the lock.

tryLockRead

Attempt to lock this reader/writer lock for read. Return 0 on success, and a non‐zero value if the lock is currently locked for write or if there are writers waiting for this lock. If successful, unlock must be used to release this lock.

tryLockWrite

Attempt to lock this reader/writer lock for write. Return 0 on success, and a non‐zero value if the lock already locked for read or write. If successful, unlock must be called to release the lock.

tryUpgradeToWriteLock

Attempt to atomically convert a read lock (acquired by a successful call to lockRead, lockReadReserveWrite, or tryLockRead) to a write lock. Return 0 on success, and a non‐zero value otherwise. If a write lock request is already pending, a non‐zero value is immediately returned. If there are other active read locks, the call will block until all current read locks are released. Note that locks that were acquired through lockReadReserveWrite are guaranteed to succeed.

unlock

Release a read lock that was previously acquired from a successful call to lockRead, lockReadReserveWrite, or tryLockRead, or a write lock which was previously acquired by a successful call to lockWrite, tryLockWrite, or upgradeToWriteLock. Note that the behavior is undefined unless the calling thread currently owns this read/write lock.

unlockRead

DEPRECATED: Use unlock instead. Note that calls to this function are simply forwarded to unlock.

unlockReadUnreserveWrite

DEPRECATED: Use unlock instead. Note that calls to this function are simply forwarded to unlock.

unlockWrite

DEPRECATED: Use unlock instead. Note that calls to this function are simply forwarded to unlock.

upgradeToWriteLock

Convert a read lock (acquired by a successful call to lockRead, lockReadReserveWrite, or tryLockRead) to a write lock. Return 0 if the upgrade operation was atomic, and a non‐zero value otherwise. If there are other active read locks, the call will block until all current read locks are released. Note that locks that were acquired through lockReadReserveWrite are guaranteed to upgrade atomically. Use unlock to release this lock.

Created with MrDocs