absl::Mutex

A non-reentrant mutually exclusive lock that also supports reader-writer locking and conditional critical regions.

Synopsis

Declared in <absl/synchronization/mutex.h>

class Mutex;

Type Aliases

NameDescription
MuHow A constant that indicates how a lock should be acquired.

Member Functions

NameDescription
Mutex [constructor]Constructors
~Mutex [destructor]Destroys this Mutex.
AssertHeld Requires that the mutex be held exclusively (write mode) by this thread.
AssertNotHeld Asserts that this thread does not hold this Mutex in any mode.
AssertReaderHeld Requires that the mutex be held at least in shared mode (read mode) by this thread.
Await Unlocks this Mutex and blocks until cond is true and the Mutex can be reacquired, then reacquires it in the same mode.
AwaitWithDeadline Unlocks this Mutex and blocks until cond is true or the deadline passes, then reacquires it in the same mode.
AwaitWithTimeout Unlocks this Mutex and blocks until cond is true or the timeout expires, then reacquires it in the same mode.
EnableDebugLog Causes all subsequent uses of this Mutex to be logged.
EnableInvariantDebugging Registers an invariant predicate to be checked for this Mutex when invariant debugging has been enabled globally.
ForgetDeadlockInfo Forgets any deadlock-detection information previously gathered about this Mutex.
Lock [deprecated]Deprecated alias for lock().
LockWhen Blocks until cond is true and the Mutex can be acquired, then atomically acquires it exclusively.
LockWhenWithDeadline Blocks until cond is true or the deadline passes, then atomically acquires this Mutex exclusively.
LockWhenWithTimeout Blocks until cond is true or the timeout expires, then atomically acquires this Mutex exclusively.
ReaderLock [deprecated]Deprecated alias for lock_shared().
ReaderLockWhen Blocks until cond is true and the Mutex can be acquired, then atomically acquires it in shared mode.
ReaderLockWhenWithDeadline Blocks until cond is true or the deadline passes, then atomically acquires this Mutex in shared mode.
ReaderLockWhenWithTimeout Blocks until cond is true or the timeout expires, then atomically acquires this Mutex in shared mode.
ReaderTryLock [deprecated]Deprecated alias for try_lock_shared().
ReaderUnlock [deprecated]Deprecated alias for unlock_shared().
TryLock [deprecated]Deprecated alias for try_lock().
Unlock [deprecated]Deprecated alias for unlock().
WriterLock [deprecated]Deprecated writer alias for lock().
WriterLockWhen Blocks until cond is true and the Mutex can be acquired, then atomically acquires it in write (exclusive) mode.
WriterLockWhenWithDeadline Blocks until cond is true or the deadline passes, then atomically acquires this Mutex in write (exclusive) mode.
WriterLockWhenWithTimeout Blocks until cond is true or the timeout expires, then atomically acquires this Mutex in write (exclusive) mode.
WriterTryLock [deprecated]Deprecated writer alias for try_lock().
WriterUnlock [deprecated]Deprecated writer alias for unlock().
lock Blocks the calling thread, if necessary, until this Mutex is free, and then acquires it exclusively.
lock_shared Blocks the calling thread, if necessary, until this Mutex is either free or in shared mode, and then acquires a share of it.
try_lock Tries to acquire this Mutex exclusively without blocking.
try_lock_shared Tries to acquire this Mutex for shared access without blocking.
unlock Releases this Mutex and returns it from the exclusive/write state to the free state.
unlock_shared Releases a read share of this Mutex.

Static Member Functions

NameDescription
InternalAttemptToUseMutexInFatalSignalHandler Prepares the Mutex implementation for re-entry from within a fatal signal handler.

Friends

NameDescription
absl::CondVarA condition variable that can be signaled to wake threads waiting on state evaluated outside a Mutex.