From 1f99f5473c7a03c791ea20256c7fc2f1caba8adc Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 19 Jan 2021 21:07:07 -0800 Subject: kernel: k_light_lock: Simplify EmuThreadHandle implementation. --- src/core/hle/kernel/k_light_lock.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/core/hle/kernel/k_light_lock.cpp') diff --git a/src/core/hle/kernel/k_light_lock.cpp b/src/core/hle/kernel/k_light_lock.cpp index 08fa65fd5..1d54ba5df 100644 --- a/src/core/hle/kernel/k_light_lock.cpp +++ b/src/core/hle/kernel/k_light_lock.cpp @@ -9,6 +9,12 @@ namespace Kernel { +static KThread* ToThread(uintptr_t thread_) { + ASSERT((thread_ & EmuThreadHandleReserved) == 0); + ASSERT((thread_ & 1) == 0); + return reinterpret_cast(thread_); +} + void KLightLock::Lock() { const uintptr_t cur_thread = reinterpret_cast(GetCurrentThreadPointer(kernel)); const uintptr_t cur_thread_tag = (cur_thread | 1); @@ -42,7 +48,7 @@ void KLightLock::Unlock() { } void KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) { - KThread* cur_thread = reinterpret_cast(_cur_thread); + KThread* cur_thread = ToThread(_cur_thread); // Pend the current thread waiting on the owner thread. { @@ -54,7 +60,7 @@ void KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) { } // Add the current thread as a waiter on the owner. - KThread* owner_thread = reinterpret_cast(_owner & ~1ul); + KThread* owner_thread = ToThread(_owner & ~1ul); cur_thread->SetAddressKey(reinterpret_cast(std::addressof(tag))); owner_thread->AddWaiter(cur_thread); @@ -82,7 +88,7 @@ void KLightLock::LockSlowPath(uintptr_t _owner, uintptr_t _cur_thread) { } void KLightLock::UnlockSlowPath(uintptr_t _cur_thread) { - KThread* owner_thread = reinterpret_cast(_cur_thread); + KThread* owner_thread = ToThread(_cur_thread); // Unlock. { -- cgit v1.2.3