supervisor_thread.h 1.4 KB

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