*/
#include <folly/MicroLock.h>
+#include <thread>
namespace folly {
}
(void)wordPtr->futexWait(newWord, slotHeldBit);
} else if (spins > maxSpins) {
- sched_yield();
+ // sched_yield(), but more portable
+ std::this_thread::yield();
+ } else {
+ folly::asm_pause();
}
oldWord = wordPtr->load(std::memory_order_relaxed);
goto retry;
newWord = oldWord | slotHeldBit;
if (!wordPtr->compare_exchange_weak(oldWord,
newWord,
- std::memory_order_relaxed,
+ std::memory_order_acquire,
std::memory_order_relaxed)) {
goto retry;
}
-
- // Locks are traditionally memory barriers, so we emit a full fence
- // even though we were happy using relaxed atomics for the
- // lock itself.
- std::atomic_thread_fence(std::memory_order_seq_cst);
}
}
oldWord | heldBit(slot),
std::memory_order_acquire,
std::memory_order_relaxed)) {
- // Fast uncontended case: seq_cst above is our memory barrier
+ // Fast uncontended case: memory_order_acquire above is our barrier
} else {
// lockSlowPath doesn't have any slot-dependent computation; it
// just shifts the input bit. Make sure its shifting produces the