diff options
author | Abseil Team <absl-team@google.com> | 2021-12-23 10:59:35 -0800 |
---|---|---|
committer | rogeeff <rogeeff@google.com> | 2021-12-25 10:10:59 -0500 |
commit | d758735198573d04e3b01b8495a4bbdb1a0d5f90 (patch) | |
tree | a1fdd70b405d6e5166bd0d43b56e0b4099f52b86 /absl/base | |
parent | f523d0dd69806d8057a898bb2595910558156aaa (diff) |
Export of internal Abseil changes
--
cca8a0c0d709803ce3413861ccbdb1b47e8fdcef by Abseil Team <absl-team@google.com>:
Add AssertHeld() to SpinLock.
PiperOrigin-RevId: 418034654
--
9e95a0e614b4cd7929d8db4324ca69d7be5351b2 by Evan Brown <ezb@google.com>:
Make btree use an unsigned size_type (size_t).
This brings btree in line with std::set, et al., which are required to use an unsigned size type - see https://en.cppreference.com/w/cpp/container/set.
Also avoid some warnings about comparing integers of different signs.
PiperOrigin-RevId: 418014466
GitOrigin-RevId: cca8a0c0d709803ce3413861ccbdb1b47e8fdcef
Change-Id: I2b951cf1d69a3bb9c8dc236c69ab4a06b45047ea
Diffstat (limited to 'absl/base')
-rw-r--r-- | absl/base/internal/spinlock.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/absl/base/internal/spinlock.h b/absl/base/internal/spinlock.h index ac40daff..6d8d8ddd 100644 --- a/absl/base/internal/spinlock.h +++ b/absl/base/internal/spinlock.h @@ -120,6 +120,14 @@ class ABSL_LOCKABLE SpinLock { return (lockword_.load(std::memory_order_relaxed) & kSpinLockHeld) != 0; } + // Return immediately if this thread holds the SpinLock exclusively. + // Otherwise, report an error by crashing with a diagnostic. + inline void AssertHeld() const ABSL_ASSERT_EXCLUSIVE_LOCK() { + if (!IsHeld()) { + ABSL_RAW_LOG(FATAL, "thread should hold the lock on SpinLock"); + } + } + protected: // These should not be exported except for testing. |