From 7047bf6ec82a9c72b1212bf6df8d3e521a354ea6 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 29 Jul 2023 15:37:34 +0300 Subject: [PATCH] [Mutex[ Request reschedule when acquiring mutex --- src/core/kernel/threads.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/kernel/threads.cpp b/src/core/kernel/threads.cpp index 8dd6f9e2..aff9028e 100644 --- a/src/core/kernel/threads.cpp +++ b/src/core/kernel/threads.cpp @@ -220,7 +220,13 @@ void Kernel::acquireSyncObject(KernelObject* object, const Thread& thread) { case KernelObjectType::Mutex: { Mutex* moo = object->getData(); - moo->locked = true; // Set locked to true, whether it's false or not because who cares + + // Only reschedule if we're acquiring the mutex for the first time + if (!moo->locked) { + moo->locked = true; + requireReschedule(); + } + // Increment lock count by 1. If a thread acquires a mootex multiple times, it needs to release it until count == 0 // For the mootex to be free. moo->lockCount++;