WaitQueue.cpp 609 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <Kernel/Thread.h>
  2. #include <Kernel/WaitQueue.h>
  3. WaitQueue::WaitQueue()
  4. {
  5. }
  6. WaitQueue::~WaitQueue()
  7. {
  8. }
  9. void WaitQueue::enqueue(Thread& thread)
  10. {
  11. InterruptDisabler disabler;
  12. m_threads.append(&thread);
  13. }
  14. void WaitQueue::wake_one()
  15. {
  16. InterruptDisabler disabler;
  17. if (m_threads.is_empty())
  18. return;
  19. if (auto* thread = m_threads.take_first())
  20. thread->wake_from_queue();
  21. }
  22. void WaitQueue::wake_all()
  23. {
  24. InterruptDisabler disabler;
  25. if (m_threads.is_empty())
  26. return;
  27. while (!m_threads.is_empty())
  28. m_threads.take_first()->wake_from_queue();
  29. }