Commit 2c47e581 authored by Benoit Lize's avatar Benoit Lize Committed by Commit Bot

[PartitionAlloc] Make SpinningFutex's spinning path more like SpinLock.

That is:
- Increase the number of spinning iterations
- Do a relaxed atomic check before the CAS in the spin loop.

Bug: 1125999, 1061437
Change-Id: I4f33376b55206dff9557a9ee59109aeaa06b5a56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424310Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809714}
parent a0dac7eb
......@@ -56,8 +56,9 @@ class BASE_EXPORT SpinningFutex {
static constexpr int kLockedUncontended = 1;
static constexpr int kLockedContended = 2;
// Same as SpinLock, not scientifically calibrated.
static constexpr int kSpinCount = 10;
// Same as SpinLock, not scientifically calibrated. Consider lowering later,
// as the slow path has better characteristics than SpinLocks's.
static constexpr int kSpinCount = 1000;
std::atomic<int32_t> state_{kUnlocked};
};
......@@ -78,7 +79,8 @@ ALWAYS_INLINE void SpinningFutex::Acquire() {
ALWAYS_INLINE bool SpinningFutex::Try() {
int expected = kUnlocked;
return state_.compare_exchange_strong(expected, kLockedUncontended,
return (state_.load(std::memory_order_relaxed) == expected) &&
state_.compare_exchange_strong(expected, kLockedUncontended,
std::memory_order_acquire,
std::memory_order_relaxed);
}
......
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