WaitQueue.h 907 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Atomic.h>
  8. #include <Kernel/Locking/Spinlock.h>
  9. #include <Kernel/Thread.h>
  10. namespace Kernel {
  11. class WaitQueue final : public Thread::BlockerSet {
  12. public:
  13. u32 wake_one();
  14. u32 wake_n(u32 wake_count);
  15. u32 wake_all();
  16. template<class... Args>
  17. Thread::BlockResult wait_on(const Thread::BlockTimeout& timeout, Args&&... args)
  18. {
  19. return Thread::current()->block<Thread::WaitQueueBlocker>(timeout, *this, forward<Args>(args)...);
  20. }
  21. template<class... Args>
  22. void wait_forever(Args&&... args)
  23. {
  24. (void)Thread::current()->block<Thread::WaitQueueBlocker>({}, *this, forward<Args>(args)...);
  25. }
  26. protected:
  27. virtual bool should_add_blocker(Thread::Blocker& b, void*) override;
  28. private:
  29. bool m_wake_requested { false };
  30. };
  31. }