From 4e14eed7708017cd2f230fa4eb7b565c023c1368 Mon Sep 17 00:00:00 2001 From: Romain Hedouin Date: Thu, 8 Oct 2026 17:21:36 +0200 Subject: [PATCH] kernel: start the semaphore wait timer after the early returns (#1173) Wait() read the clock and looked up the thread id before checking for an available token. Both are only needed once the thread has to block. --- src/kernel/semaphore.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/kernel/semaphore.cpp b/src/kernel/semaphore.cpp index e71b45bcb..37217532d 100644 --- a/src/kernel/semaphore.cpp +++ b/src/kernel/semaphore.cpp @@ -198,12 +198,6 @@ KernelSemaPrivate::Result KernelSemaPrivate::Wait(int need_count, uint32_t* ptr_ infinitely = false; } - uint32_t elapsed = 0; - Common::Timer t; - t.Start(); - - int id = Common::Thread::GetThreadIdUnique(); - if (m_count >= need_count) { m_count -= need_count; if (ptr_micros != nullptr) { @@ -216,6 +210,12 @@ KernelSemaPrivate::Result KernelSemaPrivate::Wait(int need_count, uint32_t* ptr_ return Result::TimedOut; } + uint32_t elapsed = 0; + Common::Timer t; + t.Start(); + + int id = Common::Thread::GetThreadIdUnique(); + WaitingThread waiter {}; waiter.id = id; waiter.priority = (m_fifo_order ? 0 : Libs::LibKernel::PthreadGetCurrentPriorityForKernel());