evtqueue.hpp 826 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <types/list.hpp>
  3. #include <types/lock.hpp>
  4. // declaration in kernel/process.hpp
  5. struct thread;
  6. namespace kernel {
  7. struct evt {
  8. thread* emitter;
  9. void* data1;
  10. void* data2;
  11. void* data3;
  12. };
  13. class evtqueue {
  14. public:
  15. // TODO: use small object allocator
  16. using evt_list_type = types::list<evt>;
  17. using subscriber_list_type = types::list<thread*>;
  18. private:
  19. types::mutex m_mtx;
  20. evt_list_type m_evts;
  21. subscriber_list_type m_subscribers;
  22. public:
  23. evtqueue(void) = default;
  24. evtqueue(const evtqueue&) = delete;
  25. evtqueue(evtqueue&&);
  26. void push(evt&& event);
  27. evt&& front();
  28. const evt* peek(void) const;
  29. bool empty(void) const;
  30. void notify(void);
  31. void subscribe(thread* thd);
  32. void unsubscribe(thread* thd);
  33. };
  34. } // namespace kernel