From ec29feb4978b7c468b6efc6956594fc62d80eba9 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 21 Feb 2023 08:08:08 -0700 Subject: [PATCH] kern: simplify KSchedulerLock::Lock --- .../include/mesosphere/kern_k_scheduler_lock.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libmesosphere/include/mesosphere/kern_k_scheduler_lock.hpp b/libmesosphere/include/mesosphere/kern_k_scheduler_lock.hpp index 14ff730b..d96d2e55 100644 --- a/libmesosphere/include/mesosphere/kern_k_scheduler_lock.hpp +++ b/libmesosphere/include/mesosphere/kern_k_scheduler_lock.hpp @@ -49,9 +49,9 @@ namespace ams::kern { MESOSPHERE_ASSERT_THIS(); if (this->IsLockedByCurrentThread()) { - /* If we already own the lock, we can just increment the count. */ + /* If we already own the lock, the lock count should be > 0. */ + /* For debug, ensure this is true. */ MESOSPHERE_ASSERT(m_lock_count > 0); - m_lock_count++; } else { /* Otherwise, we want to disable scheduling and acquire the spinlock. */ SchedulerType::DisableScheduling(); @@ -61,10 +61,12 @@ namespace ams::kern { MESOSPHERE_ASSERT(m_lock_count == 0); MESOSPHERE_ASSERT(m_owner_thread == nullptr); - /* Increment count, take ownership. */ - m_lock_count = 1; + /* Take ownership of the lock. */ m_owner_thread = GetCurrentThreadPointer(); } + + /* Increment the lock count. */ + m_lock_count++; } MESOSPHERE_ALWAYS_INLINE_IF_RELEASE void Unlock() {