summaryrefslogtreecommitdiff
path: root/absl/synchronization/mutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/synchronization/mutex.h')
-rw-r--r--absl/synchronization/mutex.h56
1 files changed, 44 insertions, 12 deletions
diff --git a/absl/synchronization/mutex.h b/absl/synchronization/mutex.h
index f2bafa97..6459053b 100644
--- a/absl/synchronization/mutex.h
+++ b/absl/synchronization/mutex.h
@@ -324,7 +324,9 @@ class ABSL_LOCKABLE Mutex {
// `true`, `Await()` *may* skip the release/re-acquire step.
//
// `Await()` requires that this thread holds this `Mutex` in some mode.
- void Await(const Condition& cond);
+ void Await(const Condition& cond) {
+ AwaitCommon(cond, synchronization_internal::KernelTimeout::Never());
+ }
// Mutex::LockWhen()
// Mutex::ReaderLockWhen()
@@ -334,9 +336,15 @@ class ABSL_LOCKABLE Mutex {
// be acquired, then atomically acquires this `Mutex`. `LockWhen()` is
// logically equivalent to `*Lock(); Await();` though they may have different
// performance characteristics.
- void LockWhen(const Condition& cond) ABSL_EXCLUSIVE_LOCK_FUNCTION();
+ void LockWhen(const Condition& cond) ABSL_EXCLUSIVE_LOCK_FUNCTION() {
+ LockWhenCommon(cond, synchronization_internal::KernelTimeout::Never(),
+ true);
+ }
- void ReaderLockWhen(const Condition& cond) ABSL_SHARED_LOCK_FUNCTION();
+ void ReaderLockWhen(const Condition& cond) ABSL_SHARED_LOCK_FUNCTION() {
+ LockWhenCommon(cond, synchronization_internal::KernelTimeout::Never(),
+ false);
+ }
void WriterLockWhen(const Condition& cond) ABSL_EXCLUSIVE_LOCK_FUNCTION() {
this->LockWhen(cond);
@@ -363,9 +371,13 @@ class ABSL_LOCKABLE Mutex {
// Negative timeouts are equivalent to a zero timeout.
//
// This method requires that this thread holds this `Mutex` in some mode.
- bool AwaitWithTimeout(const Condition& cond, absl::Duration timeout);
+ bool AwaitWithTimeout(const Condition& cond, absl::Duration timeout) {
+ return AwaitCommon(cond, synchronization_internal::KernelTimeout{timeout});
+ }
- bool AwaitWithDeadline(const Condition& cond, absl::Time deadline);
+ bool AwaitWithDeadline(const Condition& cond, absl::Time deadline) {
+ return AwaitCommon(cond, synchronization_internal::KernelTimeout{deadline});
+ }
// Mutex::LockWhenWithTimeout()
// Mutex::ReaderLockWhenWithTimeout()
@@ -379,9 +391,15 @@ class ABSL_LOCKABLE Mutex {
//
// Negative timeouts are equivalent to a zero timeout.
bool LockWhenWithTimeout(const Condition& cond, absl::Duration timeout)
- ABSL_EXCLUSIVE_LOCK_FUNCTION();
+ ABSL_EXCLUSIVE_LOCK_FUNCTION() {
+ return LockWhenCommon(
+ cond, synchronization_internal::KernelTimeout{timeout}, true);
+ }
bool ReaderLockWhenWithTimeout(const Condition& cond, absl::Duration timeout)
- ABSL_SHARED_LOCK_FUNCTION();
+ ABSL_SHARED_LOCK_FUNCTION() {
+ return LockWhenCommon(
+ cond, synchronization_internal::KernelTimeout{timeout}, false);
+ }
bool WriterLockWhenWithTimeout(const Condition& cond, absl::Duration timeout)
ABSL_EXCLUSIVE_LOCK_FUNCTION() {
return this->LockWhenWithTimeout(cond, timeout);
@@ -399,9 +417,15 @@ class ABSL_LOCKABLE Mutex {
//
// Deadlines in the past are equivalent to an immediate deadline.
bool LockWhenWithDeadline(const Condition& cond, absl::Time deadline)
- ABSL_EXCLUSIVE_LOCK_FUNCTION();
+ ABSL_EXCLUSIVE_LOCK_FUNCTION() {
+ return LockWhenCommon(
+ cond, synchronization_internal::KernelTimeout{deadline}, true);
+ }
bool ReaderLockWhenWithDeadline(const Condition& cond, absl::Time deadline)
- ABSL_SHARED_LOCK_FUNCTION();
+ ABSL_SHARED_LOCK_FUNCTION() {
+ return LockWhenCommon(
+ cond, synchronization_internal::KernelTimeout{deadline}, false);
+ }
bool WriterLockWhenWithDeadline(const Condition& cond, absl::Time deadline)
ABSL_EXCLUSIVE_LOCK_FUNCTION() {
return this->LockWhenWithDeadline(cond, deadline);
@@ -500,6 +524,8 @@ class ABSL_LOCKABLE Mutex {
// Common code between Await() and AwaitWithTimeout/Deadline()
bool AwaitCommon(const Condition& cond,
synchronization_internal::KernelTimeout t);
+ bool LockWhenCommon(const Condition& cond,
+ synchronization_internal::KernelTimeout t, bool write);
// Attempt to remove thread s from queue.
void TryRemove(base_internal::PerThreadSynch* s);
// Block a thread on mutex.
@@ -888,7 +914,9 @@ class CondVar {
// spurious wakeup), then reacquires the `Mutex` and returns.
//
// Requires and ensures that the current thread holds the `Mutex`.
- void Wait(Mutex* mu);
+ void Wait(Mutex* mu) {
+ WaitCommon(mu, synchronization_internal::KernelTimeout::Never());
+ }
// CondVar::WaitWithTimeout()
//
@@ -903,7 +931,9 @@ class CondVar {
// to return `true` or `false`.
//
// Requires and ensures that the current thread holds the `Mutex`.
- bool WaitWithTimeout(Mutex* mu, absl::Duration timeout);
+ bool WaitWithTimeout(Mutex* mu, absl::Duration timeout) {
+ return WaitCommon(mu, synchronization_internal::KernelTimeout(timeout));
+ }
// CondVar::WaitWithDeadline()
//
@@ -920,7 +950,9 @@ class CondVar {
// to return `true` or `false`.
//
// Requires and ensures that the current thread holds the `Mutex`.
- bool WaitWithDeadline(Mutex* mu, absl::Time deadline);
+ bool WaitWithDeadline(Mutex* mu, absl::Time deadline) {
+ return WaitCommon(mu, synchronization_internal::KernelTimeout(deadline));
+ }
// CondVar::Signal()
//