25 #include "absl/base/internal/spinlock_win32.inc" 26 #elif defined(__linux__) 27 #include "absl/base/internal/spinlock_linux.inc" 28 #elif defined(__akaros__) 29 #include "absl/base/internal/spinlock_akaros.inc" 31 #include "absl/base/internal/spinlock_posix.inc" 35 namespace base_internal {
43 uint32_t
v = w->load(std::memory_order_acquire);
45 for (i = 0; i != n && v != trans[
i].
from; i++) {
49 }
else if (trans[i].
to == v ||
50 w->compare_exchange_strong(v, trans[i].
to,
51 std::memory_order_acquire,
52 std::memory_order_relaxed)) {
53 if (trans[i].done)
return v;
64 uint64_t r = delay_rand.load(std::memory_order_relaxed);
65 r = 0x5deece66dLL * r + 0xb;
66 delay_rand.store(r, std::memory_order_relaxed);
68 if (loop < 0 || loop > 32) {
71 const int kMinDelay = 128 << 10;
73 int delay = kMinDelay << (loop / 8);
75 return delay | ((delay - 1) & static_cast<int>(r));
void SpinLockDelay(std::atomic< uint32_t > *w, uint32_t value, int loop, base_internal::SchedulingMode scheduling_mode)
uint32_t SpinLockWait(std::atomic< uint32_t > *w, int n, const SpinLockWaitTransition trans[], base_internal::SchedulingMode scheduling_mode)
static std::atomic< uint64_t > delay_rand
int SpinLockSuggestedDelayNS(int loop)