k_light_lock.h 768 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2021 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. #include "common/common_types.h"
  7. #include "core/hle/kernel/k_scoped_lock.h"
  8. namespace Kernel {
  9. class KernelCore;
  10. class KLightLock {
  11. public:
  12. explicit KLightLock(KernelCore& kernel_) : kernel{kernel_} {}
  13. void Lock();
  14. void Unlock();
  15. void LockSlowPath(uintptr_t owner, uintptr_t cur_thread);
  16. void UnlockSlowPath(uintptr_t cur_thread);
  17. bool IsLocked() const {
  18. return tag != 0;
  19. }
  20. bool IsLockedByCurrentThread() const;
  21. private:
  22. std::atomic<uintptr_t> tag{};
  23. KernelCore& kernel;
  24. };
  25. using KScopedLightLock = KScopedLock<KLightLock>;
  26. } // namespace Kernel