Commit 3602cd9d authored by Anton Bikineev's avatar Anton Bikineev Committed by Commit Bot

PartitionAlloc: Fix 'PA Everywhere' build

API was not changed.

base: :Lock was reverted, but apparently code that relied on its extended
Change-Id: I053e46378c41b9a0c8da99db57695ba4ed6894d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418679
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808819}
parent f37a0083
......@@ -849,13 +849,13 @@ void PartitionAllocator<thread_safe>::init(
PartitionAllocatorAlignment alignment,
bool with_thread_cache) {
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
CHECK(!with_thread_cache)
<< "Cannot use a thread cache when PartitionAlloc is malloc()."
PA_CHECK(!with_thread_cache)
<< "Cannot use a thread cache when PartitionAlloc is malloc().";
#endif
partition_root_.Init(alignment ==
PartitionAllocatorAlignment::
kAlignedAlloc /* enforce_alignment */,
with_thread_cache);
partition_root_.Init(
alignment ==
PartitionAllocatorAlignment::kAlignedAlloc /* enforce_alignment */,
with_thread_cache);
PartitionAllocMemoryReclaimer::Instance()->RegisterPartition(
&partition_root_);
}
......
......@@ -69,6 +69,12 @@ class BASE_EXPORT SpinLock {
AcquireSlow();
}
ALWAYS_INLINE bool Try() {
// Faster than simple CAS.
return !lock_.load(std::memory_order_relaxed) &&
!lock_.exchange(true, std::memory_order_acquire);
}
ALWAYS_INLINE void Release() {
lock_.store(false, std::memory_order_release);
}
......
......@@ -44,6 +44,7 @@ class BASE_EXPORT SpinningFutex {
inline constexpr SpinningFutex();
ALWAYS_INLINE void Acquire();
ALWAYS_INLINE void Release();
ALWAYS_INLINE bool Try();
void AssertAcquired() const {} // Not supported.
private:
......@@ -66,12 +67,8 @@ ALWAYS_INLINE void SpinningFutex::Acquire() {
// Busy-waiting is inlined, which is fine as long as we have few callers. This
// is only used for the partition lock, so this is the case.
do {
int expected = kUnlocked;
if (LIKELY(state_.compare_exchange_strong(expected, kLockedUncontended,
std::memory_order_acquire,
std::memory_order_relaxed))) {
if (LIKELY(Try()))
return;
}
YIELD_PROCESSOR;
tries++;
} while (tries < kSpinCount);
......@@ -79,6 +76,13 @@ ALWAYS_INLINE void SpinningFutex::Acquire() {
LockSlow();
}
ALWAYS_INLINE bool SpinningFutex::Try() {
int expected = kUnlocked;
return state_.compare_exchange_strong(expected, kLockedUncontended,
std::memory_order_acquire,
std::memory_order_relaxed);
}
inline constexpr SpinningFutex::SpinningFutex() = default;
ALWAYS_INLINE void SpinningFutex::Release() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment