Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

winrt_timer_scheduler.hpp 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // detail/winrt_timer_scheduler.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP
  11. #define ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_WINDOWS_RUNTIME)
  17. #include <cstddef>
  18. #include "asio/detail/event.hpp"
  19. #include "asio/detail/limits.hpp"
  20. #include "asio/detail/mutex.hpp"
  21. #include "asio/detail/op_queue.hpp"
  22. #include "asio/detail/thread.hpp"
  23. #include "asio/detail/timer_queue_base.hpp"
  24. #include "asio/detail/timer_queue_set.hpp"
  25. #include "asio/detail/wait_op.hpp"
  26. #include "asio/io_context.hpp"
  27. #if defined(ASIO_HAS_IOCP)
  28. # include "asio/detail/thread.hpp"
  29. #endif // defined(ASIO_HAS_IOCP)
  30. #include "asio/detail/push_options.hpp"
  31. namespace asio {
  32. namespace detail {
  33. class winrt_timer_scheduler
  34. : public asio::detail::service_base<winrt_timer_scheduler>
  35. {
  36. public:
  37. // Constructor.
  38. ASIO_DECL winrt_timer_scheduler(asio::io_context& io_context);
  39. // Destructor.
  40. ASIO_DECL ~winrt_timer_scheduler();
  41. // Destroy all user-defined handler objects owned by the service.
  42. ASIO_DECL void shutdown();
  43. // Recreate internal descriptors following a fork.
  44. ASIO_DECL void notify_fork(
  45. asio::io_context::fork_event fork_ev);
  46. // Initialise the task. No effect as this class uses its own thread.
  47. ASIO_DECL void init_task();
  48. // Add a new timer queue to the reactor.
  49. template <typename Time_Traits>
  50. void add_timer_queue(timer_queue<Time_Traits>& queue);
  51. // Remove a timer queue from the reactor.
  52. template <typename Time_Traits>
  53. void remove_timer_queue(timer_queue<Time_Traits>& queue);
  54. // Schedule a new operation in the given timer queue to expire at the
  55. // specified absolute time.
  56. template <typename Time_Traits>
  57. void schedule_timer(timer_queue<Time_Traits>& queue,
  58. const typename Time_Traits::time_type& time,
  59. typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
  60. // Cancel the timer operations associated with the given token. Returns the
  61. // number of operations that have been posted or dispatched.
  62. template <typename Time_Traits>
  63. std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
  64. typename timer_queue<Time_Traits>::per_timer_data& timer,
  65. std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
  66. // Move the timer operations associated with the given timer.
  67. template <typename Time_Traits>
  68. void move_timer(timer_queue<Time_Traits>& queue,
  69. typename timer_queue<Time_Traits>::per_timer_data& to,
  70. typename timer_queue<Time_Traits>::per_timer_data& from);
  71. private:
  72. // Run the select loop in the thread.
  73. ASIO_DECL void run_thread();
  74. // Entry point for the select loop thread.
  75. ASIO_DECL static void call_run_thread(winrt_timer_scheduler* reactor);
  76. // Helper function to add a new timer queue.
  77. ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
  78. // Helper function to remove a timer queue.
  79. ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
  80. // The io_context implementation used to post completions.
  81. io_context_impl& io_context_;
  82. // Mutex used to protect internal variables.
  83. asio::detail::mutex mutex_;
  84. // Event used to wake up background thread.
  85. asio::detail::event event_;
  86. // The timer queues.
  87. timer_queue_set timer_queues_;
  88. // The background thread that is waiting for timers to expire.
  89. asio::detail::thread* thread_;
  90. // Does the background thread need to stop.
  91. bool stop_thread_;
  92. // Whether the service has been shut down.
  93. bool shutdown_;
  94. };
  95. } // namespace detail
  96. } // namespace asio
  97. #include "asio/detail/pop_options.hpp"
  98. #include "asio/detail/impl/winrt_timer_scheduler.hpp"
  99. #if defined(ASIO_HEADER_ONLY)
  100. # include "asio/detail/impl/winrt_timer_scheduler.ipp"
  101. #endif // defined(ASIO_HEADER_ONLY)
  102. #endif // defined(ASIO_WINDOWS_RUNTIME)
  103. #endif // ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP