From be47743dfa0c92a88251cb28f9d222a5943b8016 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 24 Jul 2023 22:24:21 +0300 Subject: [PATCH] Kernel: Scheduler can now block threads based on tid --- kernel/include/kernel/Scheduler.h | 1 + kernel/kernel/Scheduler.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/kernel/include/kernel/Scheduler.h b/kernel/include/kernel/Scheduler.h index 07bbef9b46..42a4ffd6d2 100644 --- a/kernel/include/kernel/Scheduler.h +++ b/kernel/include/kernel/Scheduler.h @@ -26,6 +26,7 @@ namespace Kernel void block_current_thread(Semaphore*); void unblock_threads(Semaphore*); + void unblock_thread(pid_t tid); Thread& current_thread(); static pid_t current_tid(); diff --git a/kernel/kernel/Scheduler.cpp b/kernel/kernel/Scheduler.cpp index 5242a255da..a815fe8099 100644 --- a/kernel/kernel/Scheduler.cpp +++ b/kernel/kernel/Scheduler.cpp @@ -351,7 +351,26 @@ namespace Kernel it++; } } + } + void Scheduler::unblock_thread(pid_t tid) + { + CriticalScope _; + + for (auto it = m_blocking_threads.begin(); it != m_blocking_threads.end(); it++) + { + if (it->thread->tid() == tid) + { + auto thread = it->thread; + it = m_blocking_threads.remove(it); + + // This should work as we released enough memory from active thread + static_assert(sizeof(ActiveThread) == sizeof(BlockingThread)); + MUST(m_active_threads.emplace_back(thread)); + + return; + } + } } } \ No newline at end of file