supervisor_thread.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. //
  3. // Copyright (c) 2019-2020 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  4. //
  5. // Distributed under the MIT Software License
  6. //
  7. #include "rotor/supervisor.h"
  8. #include "system_context_thread.h"
  9. namespace rotor {
  10. namespace thread {
  11. /** \struct supervisor_thread_t
  12. * \brief pure thread supervisor dedicated for blocking I/O or computing operations
  13. *
  14. * To let it work, the potentially long blocking I/O operations should
  15. * be split into smaller chunks, it should be wrapped into message, and actually
  16. * in the handler the operation should be performed. Lastly, the handler should
  17. * be tagged I/O.
  18. */
  19. struct supervisor_thread_t : public supervisor_t {
  20. /** \brief constructs new thread supervisor */
  21. inline supervisor_thread_t(supervisor_config_t &cfg) : supervisor_t{cfg} {}
  22. void start() noexcept override;
  23. void shutdown() noexcept override;
  24. void enqueue(message_ptr_t message) noexcept override;
  25. void intercept(message_ptr_t &message, const void *tag, const continuation_t &continuation) noexcept override;
  26. /** \brief updates timer and fires timer handlers, which have been expired */
  27. void update_time() noexcept;
  28. void do_start_timer(const pt::time_duration &interval, timer_handler_base_t &handler) noexcept override;
  29. void do_cancel_timer(request_id_t timer_id) noexcept override;
  30. };
  31. } // namespace thread
  32. } // namespace rotor