From c0fe4756cb81106b7e443e488cd3036c8e235c9f Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 9 Jun 2023 00:53:32 +0300 Subject: [PATCH] Kernel: SpinLocks now reschedule if they cannot aquire the lock This allows us to not actually spin doing nothing while waiting for another (not executing) to release the lock. This api won't probably work when we get to SMP --- kernel/kernel/SpinLock.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kernel/kernel/SpinLock.cpp b/kernel/kernel/SpinLock.cpp index bb653724..0d664d73 100644 --- a/kernel/kernel/SpinLock.cpp +++ b/kernel/kernel/SpinLock.cpp @@ -8,7 +8,7 @@ namespace Kernel { while (__sync_lock_test_and_set(&m_lock, 1)) while (m_lock) - __builtin_ia32_pause(); + Scheduler::get().reschedule(); } void SpinLock::unlock() @@ -27,10 +27,6 @@ namespace Kernel while (true) { - // Wait for us to be the locker or the lock being free - while (m_locker != -1 && m_locker != tid) - __builtin_ia32_pause(); - m_lock.lock(); if (m_locker == tid) {