diff options
author | Abseil Team <absl-team@google.com> | 2020-05-14 16:04:20 -0700 |
---|---|---|
committer | Andy Getz <durandal@google.com> | 2020-05-14 20:49:06 -0400 |
commit | d118d4bb115387cc52c5338221f2554a940e6d90 (patch) | |
tree | 0577459d15af3035aa51ee3869b72f6b1c4ea5a1 /absl/base/internal/spinlock.cc | |
parent | f2bc9d11e841e247c95f9f1426b367721d0a8fa6 (diff) |
Export of internal Abseil changes
--
b8e6b64b604449bb51ed0ba8e9439097f3aa8773 by Abseil Team <absl-team@google.com>:
fix typo 'implentation' -> 'implementation'
PiperOrigin-RevId: 311623471
--
2b9262a311f3329c8006835a79498edd90568acd by Matt Kulukundis <kfm@google.com>:
Internal cleanup
PiperOrigin-RevId: 311549039
--
7507ed3c28113e28f993aa634bd44a9a0d4c4a2c by Derek Mauro <dmauro@google.com>:
Delete LinkerInitialized
Now that all SpinLocks have the same scheduling mode for
their entire lives, the scheduling mode does not need to
be re-tested in the loop in LockSlow.
PiperOrigin-RevId: 311521474
--
abf5fae67e21b38cda4083aaafd7012e2c6fbb7d by Andy Getzendanner <durandal@google.com>:
Fix public target name of the random library
Import of https://github.com/abseil/abseil-cpp/pull/684
PiperOrigin-RevId: 311429555
GitOrigin-RevId: b8e6b64b604449bb51ed0ba8e9439097f3aa8773
Change-Id: Ic48f671846bda059cc46f4a0b967cc3b1a733ba0
Diffstat (limited to 'absl/base/internal/spinlock.cc')
-rw-r--r-- | absl/base/internal/spinlock.cc | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/absl/base/internal/spinlock.cc b/absl/base/internal/spinlock.cc index 7cac72f9..a7d44f3e 100644 --- a/absl/base/internal/spinlock.cc +++ b/absl/base/internal/spinlock.cc @@ -79,29 +79,6 @@ SpinLock::SpinLock(base_internal::SchedulingMode mode) ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_not_static); } -SpinLock::SpinLock(base_internal::LinkerInitialized, - base_internal::SchedulingMode mode) { - ABSL_TSAN_MUTEX_CREATE(this, 0); - if (IsCooperative(mode)) { - InitLinkerInitializedAndCooperative(); - } - // Otherwise, lockword_ is already initialized. -} - -// Static (linker initialized) spinlocks always start life as functional -// non-cooperative locks. When their static constructor does run, it will call -// this initializer to augment the lockword with the cooperative bit. By -// actually taking the lock when we do this we avoid the need for an atomic -// operation in the regular unlock path. -// -// SlowLock() must be careful to re-test for this bit so that any outstanding -// waiters may be upgraded to cooperative status. -void SpinLock::InitLinkerInitializedAndCooperative() { - Lock(); - lockword_.fetch_or(kSpinLockCooperative, std::memory_order_relaxed); - Unlock(); -} - // Monitor the lock to see if its value changes within some time period // (adaptive_spin_count loop iterations). The last value read from the lock // is returned from the method. @@ -128,6 +105,14 @@ void SpinLock::SlowLock() { if ((lock_value & kSpinLockHeld) == 0) { return; } + + base_internal::SchedulingMode scheduling_mode; + if ((lock_value & kSpinLockCooperative) != 0) { + scheduling_mode = base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL; + } else { + scheduling_mode = base_internal::SCHEDULE_KERNEL_ONLY; + } + // The lock was not obtained initially, so this thread needs to wait for // it. Record the current timestamp in the local variable wait_start_time // so the total wait time can be stored in the lockword once this thread @@ -158,12 +143,6 @@ void SpinLock::SlowLock() { } } - base_internal::SchedulingMode scheduling_mode; - if ((lock_value & kSpinLockCooperative) != 0) { - scheduling_mode = base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL; - } else { - scheduling_mode = base_internal::SCHEDULE_KERNEL_ONLY; - } // SpinLockDelay() calls into fiber scheduler, we need to see // synchronization there to avoid false positives. ABSL_TSAN_MUTEX_PRE_DIVERT(this, 0); |