diff options
Diffstat (limited to 'absl/synchronization/mutex.h')
-rw-r--r-- | absl/synchronization/mutex.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h index 8c70c4ce..52401fe3 100644 --- a/absl/synchronization/mutex.h +++ b/absl/synchronization/mutex.h @@ -331,17 +331,16 @@ class ABSL_LOCKABLE Mutex { // Mutex::AwaitWithTimeout() // Mutex::AwaitWithDeadline() // - // If `cond` is initially true, do nothing, or act as though `cond` is - // initially false. - // - // If `cond` is initially false, unlock this `Mutex` and block until - // simultaneously: + // Unlocks this `Mutex` and blocks until simultaneously: // - either `cond` is true or the {timeout has expired, deadline has passed} // and // - this `Mutex` can be reacquired, // then reacquire this `Mutex` in the same mode in which it was previously // held, returning `true` iff `cond` is `true` on return. // + // If the condition is initially `true`, the implementation *may* skip the + // release/re-acquire step and return immediately. + // // Deadlines in the past are equivalent to an immediate deadline. // Negative timeouts are equivalent to a zero timeout. // @@ -686,6 +685,11 @@ class Condition { // return processed_ >= current; // }; // mu_.Await(Condition(&reached)); + // + // NOTE: never use "mu_.AssertHeld()" instead of "mu_.AssertReadHeld()" in the + // lambda as it may be called when the mutex is being unlocked from a scope + // holding only a reader lock, which will make the assertion not fulfilled and + // crash the binary. // See class comment for performance advice. In particular, if there // might be more than one waiter for the same condition, make sure @@ -770,6 +774,8 @@ class Condition { // class CondVar { public: + // A `CondVar` allocated on the heap or on the stack can use the this + // constructor. CondVar(); ~CondVar(); @@ -901,9 +907,11 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock { }; #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX + inline constexpr Mutex::Mutex(absl::ConstInitType) : impl_(absl::kConstInit) {} #else + inline Mutex::Mutex() : mu_(0) { ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_not_static); } @@ -911,7 +919,8 @@ inline Mutex::Mutex() : mu_(0) { inline constexpr Mutex::Mutex(absl::ConstInitType) : mu_(0) {} inline CondVar::CondVar() : cv_(0) {} -#endif + +#endif // ABSL_INTERNAL_USE_NONPROD_MUTEX // static template <typename T> |