diff --git a/kernel/include/kernel/Scheduler.h b/kernel/include/kernel/Scheduler.h index e03cdd02cb..f22114ea23 100644 --- a/kernel/include/kernel/Scheduler.h +++ b/kernel/include/kernel/Scheduler.h @@ -23,6 +23,7 @@ namespace Kernel void block_current_thread(Semaphore*); void unblock_threads(Semaphore*); + // Makes sleeping or blocked thread with tid active. void unblock_thread(pid_t tid); Thread& current_thread(); diff --git a/kernel/kernel/Scheduler.cpp b/kernel/kernel/Scheduler.cpp index b47c19ea4c..5bd5e1eac5 100644 --- a/kernel/kernel/Scheduler.cpp +++ b/kernel/kernel/Scheduler.cpp @@ -351,8 +351,23 @@ namespace Kernel { if (it->thread->tid() == tid) { - auto thread = it->thread; - it = m_blocking_threads.remove(it); + Thread* thread = it->thread; + 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; + } + } + + for (auto it = m_sleeping_threads.begin(); it != m_sleeping_threads.end(); it++) + { + if (it->thread->tid() == tid) + { + Thread* thread = it->thread; + m_sleeping_threads.remove(it); // This should work as we released enough memory from active thread static_assert(sizeof(ActiveThread) == sizeof(BlockingThread));