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( ...@@ -849,13 +849,13 @@ void PartitionAllocator<thread_safe>::init(
PartitionAllocatorAlignment alignment, PartitionAllocatorAlignment alignment,
bool with_thread_cache) { bool with_thread_cache) {
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
CHECK(!with_thread_cache) PA_CHECK(!with_thread_cache)
<< "Cannot use a thread cache when PartitionAlloc is malloc()." << "Cannot use a thread cache when PartitionAlloc is malloc().";
#endif #endif
partition_root_.Init(alignment == partition_root_.Init(
PartitionAllocatorAlignment:: alignment ==
kAlignedAlloc /* enforce_alignment */, PartitionAllocatorAlignment::kAlignedAlloc /* enforce_alignment */,
with_thread_cache); with_thread_cache);
PartitionAllocMemoryReclaimer::Instance()->RegisterPartition( PartitionAllocMemoryReclaimer::Instance()->RegisterPartition(
&partition_root_); &partition_root_);
} }
......
...@@ -69,6 +69,12 @@ class BASE_EXPORT SpinLock { ...@@ -69,6 +69,12 @@ class BASE_EXPORT SpinLock {
AcquireSlow(); 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() { ALWAYS_INLINE void Release() {
lock_.store(false, std::memory_order_release); lock_.store(false, std::memory_order_release);
} }
......
...@@ -44,6 +44,7 @@ class BASE_EXPORT SpinningFutex { ...@@ -44,6 +44,7 @@ class BASE_EXPORT SpinningFutex {
inline constexpr SpinningFutex(); inline constexpr SpinningFutex();
ALWAYS_INLINE void Acquire(); ALWAYS_INLINE void Acquire();
ALWAYS_INLINE void Release(); ALWAYS_INLINE void Release();
ALWAYS_INLINE bool Try();
void AssertAcquired() const {} // Not supported. void AssertAcquired() const {} // Not supported.
private: private:
...@@ -66,12 +67,8 @@ ALWAYS_INLINE void SpinningFutex::Acquire() { ...@@ -66,12 +67,8 @@ ALWAYS_INLINE void SpinningFutex::Acquire() {
// Busy-waiting is inlined, which is fine as long as we have few callers. This // 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. // is only used for the partition lock, so this is the case.
do { do {
int expected = kUnlocked; if (LIKELY(Try()))
if (LIKELY(state_.compare_exchange_strong(expected, kLockedUncontended,
std::memory_order_acquire,
std::memory_order_relaxed))) {
return; return;
}
YIELD_PROCESSOR; YIELD_PROCESSOR;
tries++; tries++;
} while (tries < kSpinCount); } while (tries < kSpinCount);
...@@ -79,6 +76,13 @@ ALWAYS_INLINE void SpinningFutex::Acquire() { ...@@ -79,6 +76,13 @@ ALWAYS_INLINE void SpinningFutex::Acquire() {
LockSlow(); 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; inline constexpr SpinningFutex::SpinningFutex() = default;
ALWAYS_INLINE void SpinningFutex::Release() { 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