k_light_lock.h 729 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <atomic>
  5. #include "core/hle/kernel/k_scoped_lock.h"
  6. namespace Kernel {
  7. class KernelCore;
  8. class KLightLock {
  9. public:
  10. explicit KLightLock(KernelCore& kernel) : m_kernel{kernel} {}
  11. void Lock();
  12. void Unlock();
  13. bool LockSlowPath(uintptr_t owner, uintptr_t cur_thread);
  14. void UnlockSlowPath(uintptr_t cur_thread);
  15. bool IsLocked() const {
  16. return m_tag.load() != 0;
  17. }
  18. bool IsLockedByCurrentThread() const;
  19. private:
  20. std::atomic<uintptr_t> m_tag{};
  21. KernelCore& m_kernel;
  22. };
  23. using KScopedLightLock = KScopedLock<KLightLock>;
  24. } // namespace Kernel