Skip to content

Commit

Permalink
Clarify the behaviour of AssertHeld and AssertReaderHeld when the…
Browse files Browse the repository at this point in the history
… calling thread doesn't hold the mutex.

PiperOrigin-RevId: 451410449
Change-Id: Iffd4c7463f1051474debbed256703589d96a548c
  • Loading branch information
Abseil Team authored and copybara-github committed May 27, 2022
1 parent 89cdaed commit 8cc2e34
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions absl/synchronization/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,12 @@ class ABSL_LOCKABLE Mutex {

// Mutex::AssertHeld()
//
// Return immediately if this thread holds the `Mutex` exclusively (in write
// mode). Otherwise, may report an error (typically by crashing with a
// diagnostic), or may return immediately.
// Require that the mutex be held exclusively (write mode) by this thread.
//
// If the mutex is not currently held by this thread, this function may report
// an error (typically by crashing with a diagnostic) or it may do nothing.
// This function is intended only as a tool to assist debugging; it doesn't
// guarantee correctness.
void AssertHeld() const ABSL_ASSERT_EXCLUSIVE_LOCK();

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -236,9 +239,13 @@ class ABSL_LOCKABLE Mutex {

// Mutex::AssertReaderHeld()
//
// Returns immediately if this thread holds the `Mutex` in at least shared
// mode (read mode). Otherwise, may report an error (typically by
// crashing with a diagnostic), or may return immediately.
// Require that the mutex be held at least in shared mode (read mode) by this
// thread.
//
// If the mutex is not currently held by this thread, this function may report
// an error (typically by crashing with a diagnostic) or it may do nothing.
// This function is intended only as a tool to assist debugging; it doesn't
// guarantee correctness.
void AssertReaderHeld() const ABSL_ASSERT_SHARED_LOCK();

// Mutex::WriterLock()
Expand Down

0 comments on commit 8cc2e34

Please sign in to comment.