A small, fast, scalable reader‐writer lock.
Synopsis
Declared in <folly/SharedMutex.h>
template<
bool ReaderPriority,
typename Tag_ = void,
template<typename> typename Atom = atomic,
typename Policy = SharedMutexPolicyDefault>
class SharedMutexImpl;
Description
SharedMutex provides exclusive, upgrade, and shared locking modes, with blocking, try, try‐for, and try‐until variants. Each instance is only a few bytes and records shared acquisitions in a shared set of core‐local stripes so that concurrent readers scale linearly.
Type Aliases
Name |
Description |
Storage for one deferred reader slot; holds a tagged mutex pointer. |
|
Tag type used to create an independent instantiation. |
|
Token type used to speed up paired shared lock and unlock calls. |
Member Functions
Name |
Description |
|
Constructors |
|
Destroys the mutex. |
Assignment operators |
|
Checks whether an exclusive lock could succeed so that lock elision can be enabled. |
|
|
Checks whether a shared lock could succeed so that lock elision can be enabled. |
|
Checks whether an upgrade lock could succeed so that lock elision can be enabled. |
Acquires the lock in exclusive mode, blocking until it is available. |
|
|
|
Acquires the lock in upgrade mode, blocking until it is available. |
|
Invalidates the given token so the tokenless unlock_shared() can be used. |
|
Tries to acquire the lock in exclusive mode without blocking. |
|
Tries to acquire the lock in exclusive mode within a duration. |
|
|
|
|
|
|
|
Tries to acquire the lock in exclusive mode by a deadline. |
|
Tries to acquire the lock in upgrade mode without blocking. |
|
Tries to acquire the lock in upgrade mode within a duration. |
|
Tries to acquire the lock in upgrade mode by a deadline. |
|
Releases the lock held in exclusive mode. |
|
|
|
Atomically converts an exclusive lock to an upgrade lock. |
|
|
|
Releases a lock held in upgrade mode. |
|
Atomically upgrades an upgrade lock to an exclusive lock. |
|
|
Static Data Members
Name |
Description |
Number of deferred reader slots searched when acquiring or releasing. |
|
Spacing between used deferred reader slots, to avoid cache contention. |
|
Whether this instantiation gives priority to readers. |
Template Parameters
Name |
Description |
ReaderPriority |
Whether readers take priority over writers. |
Tag_ |
Tag type used to create an independent instantiation with its own deferred‐reader storage. |
Atom |
Atomic template used for the lock state and deferred slots. |
Policy |
Tuning and feature policy; see SharedMutexPolicyDefault. |
Created with MrDocs