20 #ifndef GALOIS_SUBSTRATE_SIMPLELOCK_H
21 #define GALOIS_SUBSTRATE_SIMPLELOCK_H
27 #include "galois/config.h"
37 mutable std::atomic<int> _lock;
38 void slow_lock()
const;
44 : _lock(p._lock.load(std::memory_order_relaxed)) {}
50 _lock.store(p._lock.load(std::memory_order_relaxed),
51 std::memory_order_relaxed);
57 if (_lock.load(std::memory_order_relaxed))
59 if (!_lock.compare_exchange_weak(oldval, 1, std::memory_order_acq_rel,
60 std::memory_order_relaxed))
71 _lock.store(0, std::memory_order_release);
77 if (_lock.load(std::memory_order_relaxed))
79 if (!_lock.compare_exchange_weak(oldval, 1, std::memory_order_acq_rel))
86 return _lock.load(std::memory_order_acquire) & 1;
94 inline void lock()
const {}
100 template <
bool Enabled>
102 typename std::conditional<Enabled, SimpleLock, DummyLock>::type;
106 #define MAKE_LOCK_GUARD(__x) \
107 galois::substrate::lock_guard_galois locker##___COUNTER__(__x)
SimpleLock & operator=(const SimpleLock &p)
Definition: SimpleLock.h:46
bool try_lock() const
Definition: SimpleLock.h:96
void lock() const
Definition: SimpleLock.h:94
constexpr SimpleLock()
Definition: SimpleLock.h:41
std::lock_guard< SimpleLock > lock_guard_galois
Definition: SimpleLock.h:104
bool is_locked() const
Definition: SimpleLock.h:85
typename std::conditional< Enabled, SimpleLock, DummyLock >::type CondLock
Definition: SimpleLock.h:102
bool is_locked() const
Definition: SimpleLock.h:97
void unlock() const
Definition: SimpleLock.h:68
bool try_lock() const
Definition: SimpleLock.h:75
SimpleLock(const SimpleLock &p)
Definition: SimpleLock.h:43
void unlock() const
Definition: SimpleLock.h:95
void lock() const
Definition: SimpleLock.h:55
SimpleLock is a spinlock.
Definition: SimpleLock.h:36
Dummy Lock implements the lock interface without a lock for serial code.
Definition: SimpleLock.h:92