From d758735198573d04e3b01b8495a4bbdb1a0d5f90 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 23 Dec 2021 10:59:35 -0800 Subject: Export of internal Abseil changes -- cca8a0c0d709803ce3413861ccbdb1b47e8fdcef by Abseil Team : Add AssertHeld() to SpinLock. PiperOrigin-RevId: 418034654 -- 9e95a0e614b4cd7929d8db4324ca69d7be5351b2 by Evan Brown : 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 --- absl/base/internal/spinlock.h | 8 ++++++++ absl/container/internal/btree.h | 6 +++--- 2 files changed, 11 insertions(+), 3 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. diff --git a/absl/container/internal/btree.h b/absl/container/internal/btree.h index 29603379..26bd5e14 100644 --- a/absl/container/internal/btree.h +++ b/absl/container/internal/btree.h @@ -238,7 +238,7 @@ struct common_params { using allocator_type = Alloc; using key_type = Key; - using size_type = std::make_signed::type; + using size_type = size_t; using difference_type = ptrdiff_t; using slot_policy = SlotPolicy; @@ -1497,7 +1497,7 @@ inline void btree_node

::emplace_value(const size_type i, set_finish(finish() + 1); if (!leaf() && finish() > i + 1) { - for (int j = finish(); j > i + 1; --j) { + for (field_type j = finish(); j > i + 1; --j) { set_child(j, child(j - 1)); } clear_child(i + 1); @@ -2124,7 +2124,7 @@ auto btree

::erase_range(iterator begin, iterator end) return {0, begin}; } - if (count == size_) { + if (static_cast(count) == size_) { clear(); return {count, this->end()}; } -- cgit v1.2.3