ge_spin_lock.hpp 361 B

123456789101112131415
  1. #ifndef HEADER_GE_SPIN_LOCK_HPP
  2. #define HEADER_GE_SPIN_LOCK_HPP
  3. #include <atomic>
  4. class GESpinLock
  5. {
  6. mutable std::atomic_flag m_locked = ATOMIC_FLAG_INIT;
  7. public:
  8. void lock() const
  9. { while (m_locked.test_and_set(std::memory_order_acquire)); }
  10. void unlock() const { m_locked.clear(std::memory_order_release); }
  11. };
  12. #endif