diff options
author | Abseil Team <absl-team@google.com> | 2023-02-28 10:47:58 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-02-28 10:48:54 -0800 |
commit | 1d07cfede2d0153ebfa23543ffcc08faf55b4539 (patch) | |
tree | 4943aab47003b4119f0a97d09d932d4c6b9c8a95 /absl/synchronization/mutex.cc | |
parent | cd43bea7779641790763f983f92683882749c647 (diff) | |
download | abseil-1d07cfede2d0153ebfa23543ffcc08faf55b4539.tar.gz abseil-1d07cfede2d0153ebfa23543ffcc08faf55b4539.tar.bz2 abseil-1d07cfede2d0153ebfa23543ffcc08faf55b4539.zip |
Rollback because of internal incompatibility.
PiperOrigin-RevId: 512979517
Change-Id: I7fe38ed246e42e6f8eb322e15c3b299215163168
Diffstat (limited to 'absl/synchronization/mutex.cc')
-rw-r--r-- | absl/synchronization/mutex.cc | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc index a8911614..ef6d063e 100644 --- a/absl/synchronization/mutex.cc +++ b/absl/synchronization/mutex.cc @@ -635,6 +635,21 @@ void Mutex::InternalAttemptToUseMutexInFatalSignalHandler() { std::memory_order_release); } +// --------------------------time support + +// Return the current time plus the timeout. Use the same clock as +// PerThreadSem::Wait() for consistency. Unfortunately, we don't have +// such a choice when a deadline is given directly. +static absl::Time DeadlineFromTimeout(absl::Duration timeout) { +#ifndef _WIN32 + struct timeval tv; + gettimeofday(&tv, nullptr); + return absl::TimeFromTimeval(tv) + timeout; +#else + return absl::Now() + timeout; +#endif +} + // --------------------------Mutexes // In the layout below, the msb of the bottom byte is currently unused. Also, @@ -1534,13 +1549,7 @@ void Mutex::LockWhen(const Condition &cond) { } bool Mutex::LockWhenWithTimeout(const Condition &cond, absl::Duration timeout) { - ABSL_TSAN_MUTEX_PRE_LOCK(this, 0); - GraphId id = DebugOnlyDeadlockCheck(this); - bool res = LockSlowWithDeadline(kExclusive, &cond, - KernelTimeout(timeout), 0); - DebugOnlyLockEnter(this, id); - ABSL_TSAN_MUTEX_POST_LOCK(this, 0, 0); - return res; + return LockWhenWithDeadline(cond, DeadlineFromTimeout(timeout)); } bool Mutex::LockWhenWithDeadline(const Condition &cond, absl::Time deadline) { @@ -1563,12 +1572,7 @@ void Mutex::ReaderLockWhen(const Condition &cond) { bool Mutex::ReaderLockWhenWithTimeout(const Condition &cond, absl::Duration timeout) { - ABSL_TSAN_MUTEX_PRE_LOCK(this, __tsan_mutex_read_lock); - GraphId id = DebugOnlyDeadlockCheck(this); - bool res = LockSlowWithDeadline(kShared, &cond, KernelTimeout(timeout), 0); - DebugOnlyLockEnter(this, id); - ABSL_TSAN_MUTEX_POST_LOCK(this, __tsan_mutex_read_lock, 0); - return res; + return ReaderLockWhenWithDeadline(cond, DeadlineFromTimeout(timeout)); } bool Mutex::ReaderLockWhenWithDeadline(const Condition &cond, @@ -1593,18 +1597,7 @@ void Mutex::Await(const Condition &cond) { } bool Mutex::AwaitWithTimeout(const Condition &cond, absl::Duration timeout) { - if (cond.Eval()) { // condition already true; nothing to do - if (kDebugMode) { - this->AssertReaderHeld(); - } - return true; - } - - KernelTimeout t{timeout}; - bool res = this->AwaitCommon(cond, t); - ABSL_RAW_CHECK(res || t.has_timeout(), - "condition untrue on return from Await"); - return res; + return AwaitWithDeadline(cond, DeadlineFromTimeout(timeout)); } bool Mutex::AwaitWithDeadline(const Condition &cond, absl::Time deadline) { @@ -2670,7 +2663,7 @@ bool CondVar::WaitCommon(Mutex *mutex, KernelTimeout t) { } bool CondVar::WaitWithTimeout(Mutex *mu, absl::Duration timeout) { - return WaitCommon(mu, KernelTimeout(timeout)); + return WaitWithDeadline(mu, DeadlineFromTimeout(timeout)); } bool CondVar::WaitWithDeadline(Mutex *mu, absl::Time deadline) { |