waitlist.hpp 485 B

1234567891011121314151617181920212223242526272829
  1. #pragma once
  2. #include <set>
  3. #include <kernel/async/lock.hpp>
  4. #include <kernel/task/forward.hpp>
  5. namespace kernel::async {
  6. class wait_list {
  7. private:
  8. mutex m_mtx;
  9. std::set<task::thread*> m_subscribers;
  10. wait_list(const wait_list&) = delete;
  11. public:
  12. explicit wait_list() = default;
  13. // @return whether the wait is interrupted
  14. bool wait(mutex& lck);
  15. void subscribe();
  16. void notify_one();
  17. void notify_all();
  18. };
  19. } // namespace kernel::async