SpinLock.hpp 558 B

123456789101112131415161718192021222324
  1. #ifndef CORE_SPIN_LOCK_HPP
  2. #define CORE_SPIN_LOCK_HPP
  3. // stdatomic.h is not compatible with C++
  4. // all calls are noexcept
  5. #include <atomic>
  6. using atomic_bool = std::atomic_bool;
  7. namespace Core {
  8. class SpinLock final {
  9. atomic_bool locked;
  10. public:
  11. SpinLock();
  12. SpinLock(const SpinLock& other) = delete;
  13. SpinLock(SpinLock&& other) = delete;
  14. SpinLock& operator=(const SpinLock& other) = delete;
  15. SpinLock& operator=(SpinLock&& other) = delete;
  16. void lock();
  17. void unlock();
  18. };
  19. }
  20. #endif