Guest User

Untitled

a guest
Feb 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. #include <atomic>
  2.  
  3. class atomic_spin_lock {
  4. std::atomic_flag locked = ATOMIC_FLAG_INIT ;
  5. public:
  6. void lock() noexcept {
  7. while (locked.test_and_set(std::memory_order_acquire)) { ; /* TODO cpu_relax() here for better performance */ }
  8. }
  9.  
  10. void unlock() noexcept {
  11. locked.clear(std::memory_order_release);
  12. }
  13. };
Add Comment
Please, Sign In to add comment