[#BloombergLP-bslmt-ReaderWriterLock]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::ReaderWriterLock
:relfileprefix: ../../
:mrdocs:

This class provides a multi&hyphen;reader&sol;single&hyphen;writer lock mechanism&period;

== Synopsis

Declared in `&lt;bslmt&lowbar;readerwriterlock&period;h&gt;`

[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&sol;writer lock initialized to an unlocked state&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/2destructor.adoc[`&#126;ReaderWriterLock`] [.small]#[destructor]#
| Destroy this reader&sol;writer lock&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/isLocked.adoc[`isLocked`] 
| Return `true` if this reader&hyphen;write lock is currently read locked or write locked, and `false` otherwise&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/isLockedRead.adoc[`isLockedRead`] 
| Return `true` if this reader&hyphen;write lock is currently read locked, and `false` otherwise&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/isLockedWrite.adoc[`isLockedWrite`] 
| Return `true` if this reader&hyphen;write lock is currently write locked, and `false` otherwise&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/lockRead.adoc[`lockRead`] 
| Lock this reader&sol;writer lock for read&period; If there are no pending or active write locks, the call will return immediately, otherwise it block until all write locks have been released&period; Use `unlock` to release the lock&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/lockReadReserveWrite.adoc[`lockReadReserveWrite`] 
| Lock this reader&sol;writer lock for read and reserve a write lock so that a call to `upgradeToWriteLock` is guaranteed to upgrade atomically&period; 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&period; The lock may then be atomically converted to a write lock by calling `upgradeToWriteLock`&period; Use `unlock` to release the lock&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/lockWrite.adoc[`lockWrite`] 
| Lock the reader&sol;writer lock for write&period; The call will block until all active read locks or active&sol;pending write locks are released&period; When the reader&sol;writer lock is locked for write, all read&sol;write lock attempts will either fail or block until the lock is released&period; Use `unlock` to release the lock&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/tryLockRead.adoc[`tryLockRead`] 
| Attempt to lock this reader&sol;writer lock for read&period; Return 0 on success, and a non&hyphen;zero value if the lock is currently locked for write or if there are writers waiting for this lock&period; If successful, `unlock` must be used to release this lock&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/tryLockWrite.adoc[`tryLockWrite`] 
| Attempt to lock this reader&sol;writer lock for write&period; Return 0 on success, and a non&hyphen;zero value if the lock already locked for read or write&period; If successful, `unlock` must be called to release the lock&period;
| 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&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; If a write lock request is already pending, a non&hyphen;zero value is immediately returned&period; If there are other active read locks, the call will block until all current read locks are released&period; Note that locks that were acquired through `lockReadReserveWrite` are guaranteed to succeed&period;
| 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`&period; Note that the behavior is undefined unless the calling thread currently owns this read&sol;write lock&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/unlockRead.adoc[`unlockRead`] 
| DEPRECATED&colon; Use `unlock` instead&period; Note that calls to this function are simply forwarded to `unlock`&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/unlockReadUnreserveWrite.adoc[`unlockReadUnreserveWrite`] 
| DEPRECATED&colon; Use `unlock` instead&period; Note that calls to this function are simply forwarded to `unlock`&period;
| xref:BloombergLP/bslmt/ReaderWriterLock/unlockWrite.adoc[`unlockWrite`] 
| DEPRECATED&colon; Use `unlock` instead&period; Note that calls to this function are simply forwarded to `unlock`&period;
| 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&period; Return 0 if the upgrade operation was atomic, and a non&hyphen;zero value otherwise&period; If there are other active read locks, the call will block until all current read locks are released&period; Note that locks that were acquired through `lockReadReserveWrite` are guaranteed to upgrade atomically&period; Use `unlock` to release this lock&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
