18 #ifndef FOEDUS_ASSORTED_DUMB_SPINLOCK_HPP_
19 #define FOEDUS_ASSORTED_DUMB_SPINLOCK_HPP_
42 DumbSpinlock(
bool* locked,
bool lock_initially =
true) : locked_by_me_(false), locked_(locked) {
66 bool expected =
false;
67 if (raw_atomic_compare_exchange_weak<bool>(locked_, &expected,
true)) {
81 locked_by_me_ =
false;
96 #endif // FOEDUS_ASSORTED_DUMB_SPINLOCK_HPP_
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
A simple spinlock using a boolean field.
DumbSpinlock(bool *locked, bool lock_initially=true)
bool try_lock()
try-version of the lock.
#define SPINLOCK_WHILE(x)
A macro to busy-wait (spinlock) with occasional pause.
~DumbSpinlock()
automatically unlocks when out of scope.
void lock()
Locks it if I haven't locked it yet.
void unlock()
Unlocks it if I locked it.
Atomic fence methods and load/store with fences that work for both C++11/non-C++11 code...
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
bool is_locked_by_me() const
Raw atomic operations that work for both C++11 and non-C++11 code.
void memory_fence_acq_rel()
Equivalent to std::atomic_thread_fence(std::memory_order_acq_rel).