[#BloombergLP-bslmt-ReaderWriterLock] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::ReaderWriterLock :relfileprefix: ../../ :mrdocs: This class provides a multi‐reader/single‐writer lock mechanism. == Synopsis Declared in `<bslmt_readerwriterlock.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class ReaderWriterLock; ---- == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslmt/ReaderWriterLock/2constructor.adoc[`ReaderWriterLock`] [.small]#[constructor]# | Construct a reader/writer lock initialized to an unlocked state. | xref:BloombergLP/bslmt/ReaderWriterLock/2destructor.adoc[`~ReaderWriterLock`] [.small]#[destructor]# | Destroy this reader/writer lock. | xref:BloombergLP/bslmt/ReaderWriterLock/isLocked.adoc[`isLocked`] | Return `true` if this reader‐write lock is currently read locked or write locked, and `false` otherwise. | xref:BloombergLP/bslmt/ReaderWriterLock/isLockedRead.adoc[`isLockedRead`] | Return `true` if this reader‐write lock is currently read locked, and `false` otherwise. | xref:BloombergLP/bslmt/ReaderWriterLock/isLockedWrite.adoc[`isLockedWrite`] | Return `true` if this reader‐write lock is currently write locked, and `false` otherwise. | xref:BloombergLP/bslmt/ReaderWriterLock/lockRead.adoc[`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. | xref:BloombergLP/bslmt/ReaderWriterLock/lockReadReserveWrite.adoc[`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. | xref:BloombergLP/bslmt/ReaderWriterLock/lockWrite.adoc[`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. | xref:BloombergLP/bslmt/ReaderWriterLock/tryLockRead.adoc[`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. | xref:BloombergLP/bslmt/ReaderWriterLock/tryLockWrite.adoc[`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. | xref:BloombergLP/bslmt/ReaderWriterLock/tryUpgradeToWriteLock.adoc[`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. | xref:BloombergLP/bslmt/ReaderWriterLock/unlock.adoc[`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. | xref:BloombergLP/bslmt/ReaderWriterLock/unlockRead.adoc[`unlockRead`] | DEPRECATED: Use `unlock` instead. Note that calls to this function are simply forwarded to `unlock`. | xref:BloombergLP/bslmt/ReaderWriterLock/unlockReadUnreserveWrite.adoc[`unlockReadUnreserveWrite`] | DEPRECATED: Use `unlock` instead. Note that calls to this function are simply forwarded to `unlock`. | xref:BloombergLP/bslmt/ReaderWriterLock/unlockWrite.adoc[`unlockWrite`] | DEPRECATED: Use `unlock` instead. Note that calls to this function are simply forwarded to `unlock`. | xref:BloombergLP/bslmt/ReaderWriterLock/upgradeToWriteLock.adoc[`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. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#