diff options
author | bunnei <bunneidev@gmail.com> | 2020-12-04 07:26:42 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2020-12-06 09:03:24 +0100 |
commit | ccce6cb3be062fc7ae162bed32202538ebc2e3d9 (patch) | |
tree | 206612bfc3718371d2355c8e3447aba288b1828f /src/core/hle/kernel/k_scoped_lock.h | |
parent | hle: kernel: Separate KScopedSchedulerLockAndSleep from k_scheduler. (diff) | |
download | yuzu-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.h | 39 |
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 |