spin_lock.h 510 B

1234567891011121314151617181920212223242526
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <atomic>
  6. namespace Common {
  7. /**
  8. * SpinLock class
  9. * a lock similar to mutex that forces a thread to spin wait instead calling the
  10. * supervisor. Should be used on short sequences of code.
  11. */
  12. class SpinLock {
  13. public:
  14. void lock();
  15. void unlock();
  16. bool try_lock();
  17. private:
  18. std::atomic_flag lck = ATOMIC_FLAG_INIT;
  19. };
  20. } // namespace Common