Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <atomic>
- class atomic_spin_lock {
- std::atomic_flag locked = ATOMIC_FLAG_INIT ;
- public:
- void lock() noexcept {
- while (locked.test_and_set(std::memory_order_acquire)) { ; /* TODO cpu_relax() here for better performance */ }
- }
- void unlock() noexcept {
- locked.clear(std::memory_order_release);
- }
- };
Add Comment
Please, Sign In to add comment