2019-12-01 11:57:20 +01:00
|
|
|
#include <Kernel/Thread.h>
|
|
|
|
#include <Kernel/WaitQueue.h>
|
|
|
|
|
|
|
|
WaitQueue::WaitQueue()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitQueue::~WaitQueue()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitQueue::enqueue(Thread& thread)
|
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2019-12-22 12:23:44 +01:00
|
|
|
m_threads.append(thread);
|
2019-12-01 11:57:20 +01:00
|
|
|
}
|
|
|
|
|
2020-01-12 18:46:41 +01:00
|
|
|
void WaitQueue::wake_one(Atomic<bool>* lock)
|
2019-12-01 11:57:20 +01:00
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2020-01-12 18:46:41 +01:00
|
|
|
if (lock)
|
|
|
|
*lock = false;
|
2019-12-01 11:57:20 +01:00
|
|
|
if (m_threads.is_empty())
|
|
|
|
return;
|
|
|
|
if (auto* thread = m_threads.take_first())
|
2019-12-01 15:54:47 +01:00
|
|
|
thread->wake_from_queue();
|
2019-12-08 00:33:35 +01:00
|
|
|
Scheduler::stop_idling();
|
2019-12-01 11:57:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WaitQueue::wake_all()
|
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
if (m_threads.is_empty())
|
|
|
|
return;
|
|
|
|
while (!m_threads.is_empty())
|
2019-12-01 15:54:47 +01:00
|
|
|
m_threads.take_first()->wake_from_queue();
|
2019-12-08 00:33:35 +01:00
|
|
|
Scheduler::stop_idling();
|
2019-12-01 11:57:20 +01:00
|
|
|
}
|