summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/k_scoped_lock.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-12-04 07:26:42 +0100
committerbunnei <bunneidev@gmail.com>2020-12-06 09:03:24 +0100
commitccce6cb3be062fc7ae162bed32202538ebc2e3d9 (patch)
tree206612bfc3718371d2355c8e3447aba288b1828f /src/core/hle/kernel/k_scoped_lock.h
parenthle: kernel: Separate KScopedSchedulerLockAndSleep from k_scheduler. (diff)
downloadyuzu-ccce6cb3be062fc7ae162bed32202538ebc2e3d9.tar
yuzu-ccce6cb3be062fc7ae162bed32202538ebc2e3d9.tar.gz
yuzu-ccce6cb3be062fc7ae162bed32202538ebc2e3d9.tar.bz2
yuzu-ccce6cb3be062fc7ae162bed32202538ebc2e3d9.tar.lz
yuzu-ccce6cb3be062fc7ae162bed32202538ebc2e3d9.tar.xz
yuzu-ccce6cb3be062fc7ae162bed32202538ebc2e3d9.tar.zst
yuzu-ccce6cb3be062fc7ae162bed32202538ebc2e3d9.zip
Diffstat (limited to 'src/core/hle/kernel/k_scoped_lock.h')
-rw-r--r--src/core/hle/kernel/k_scoped_lock.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_scoped_lock.h b/src/core/hle/kernel/k_scoped_lock.h
new file mode 100644
index 000000000..03320859f
--- /dev/null
+++ b/src/core/hle/kernel/k_scoped_lock.h
@@ -0,0 +1,39 @@
+// Copyright 2020 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+// This file references various implementation details from Atmosphere, an open-source firmware for
+// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
+
+#pragma once
+
+#include "common/common_types.h"
+
+namespace Kernel {
+
+template <typename T>
+concept KLockable = !std::is_reference<T>::value && requires(T & t) {
+ { t.Lock() }
+ ->std::same_as<void>;
+ { t.Unlock() }
+ ->std::same_as<void>;
+};
+
+template <typename T>
+requires KLockable<T> class KScopedLock : NonCopyable {
+
+private:
+ T* lock_ptr;
+
+public:
+ explicit KScopedLock(T* l) : lock_ptr(l) {
+ this->lock_ptr->Lock();
+ }
+ explicit KScopedLock(T& l) : KScopedLock(std::addressof(l)) { /* ... */
+ }
+ ~KScopedLock() {
+ this->lock_ptr->Unlock();
+ }
+};
+
+} // namespace Kernel