]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/winrt_timer_scheduler.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
11fdf7f2 | 5 | // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
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 | ||
11 | #ifndef BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP | |
12 | #define BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP | |
13 | ||
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) | |
15 | # pragma once | |
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) | |
17 | ||
18 | #include <boost/asio/detail/config.hpp> | |
19 | ||
20 | #if defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
21 | ||
22 | #include <cstddef> | |
23 | #include <boost/asio/detail/event.hpp> | |
24 | #include <boost/asio/detail/limits.hpp> | |
25 | #include <boost/asio/detail/mutex.hpp> | |
26 | #include <boost/asio/detail/op_queue.hpp> | |
27 | #include <boost/asio/detail/thread.hpp> | |
28 | #include <boost/asio/detail/timer_queue_base.hpp> | |
29 | #include <boost/asio/detail/timer_queue_set.hpp> | |
30 | #include <boost/asio/detail/wait_op.hpp> | |
b32b8144 | 31 | #include <boost/asio/io_context.hpp> |
7c673cae FG |
32 | |
33 | #if defined(BOOST_ASIO_HAS_IOCP) | |
34 | # include <boost/asio/detail/thread.hpp> | |
35 | #endif // defined(BOOST_ASIO_HAS_IOCP) | |
36 | ||
37 | #include <boost/asio/detail/push_options.hpp> | |
38 | ||
39 | namespace boost { | |
40 | namespace asio { | |
41 | namespace detail { | |
42 | ||
43 | class winrt_timer_scheduler | |
44 | : public boost::asio::detail::service_base<winrt_timer_scheduler> | |
45 | { | |
46 | public: | |
47 | // Constructor. | |
b32b8144 | 48 | BOOST_ASIO_DECL winrt_timer_scheduler(boost::asio::io_context& io_context); |
7c673cae FG |
49 | |
50 | // Destructor. | |
51 | BOOST_ASIO_DECL ~winrt_timer_scheduler(); | |
52 | ||
53 | // Destroy all user-defined handler objects owned by the service. | |
b32b8144 | 54 | BOOST_ASIO_DECL void shutdown(); |
7c673cae FG |
55 | |
56 | // Recreate internal descriptors following a fork. | |
b32b8144 FG |
57 | BOOST_ASIO_DECL void notify_fork( |
58 | boost::asio::io_context::fork_event fork_ev); | |
7c673cae FG |
59 | |
60 | // Initialise the task. No effect as this class uses its own thread. | |
61 | BOOST_ASIO_DECL void init_task(); | |
62 | ||
63 | // Add a new timer queue to the reactor. | |
64 | template <typename Time_Traits> | |
65 | void add_timer_queue(timer_queue<Time_Traits>& queue); | |
66 | ||
67 | // Remove a timer queue from the reactor. | |
68 | template <typename Time_Traits> | |
69 | void remove_timer_queue(timer_queue<Time_Traits>& queue); | |
70 | ||
71 | // Schedule a new operation in the given timer queue to expire at the | |
72 | // specified absolute time. | |
73 | template <typename Time_Traits> | |
74 | void schedule_timer(timer_queue<Time_Traits>& queue, | |
75 | const typename Time_Traits::time_type& time, | |
76 | typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op); | |
77 | ||
78 | // Cancel the timer operations associated with the given token. Returns the | |
79 | // number of operations that have been posted or dispatched. | |
80 | template <typename Time_Traits> | |
81 | std::size_t cancel_timer(timer_queue<Time_Traits>& queue, | |
82 | typename timer_queue<Time_Traits>::per_timer_data& timer, | |
83 | std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)()); | |
84 | ||
b32b8144 FG |
85 | // Move the timer operations associated with the given timer. |
86 | template <typename Time_Traits> | |
87 | void move_timer(timer_queue<Time_Traits>& queue, | |
88 | typename timer_queue<Time_Traits>::per_timer_data& to, | |
89 | typename timer_queue<Time_Traits>::per_timer_data& from); | |
90 | ||
7c673cae FG |
91 | private: |
92 | // Run the select loop in the thread. | |
93 | BOOST_ASIO_DECL void run_thread(); | |
94 | ||
95 | // Entry point for the select loop thread. | |
96 | BOOST_ASIO_DECL static void call_run_thread(winrt_timer_scheduler* reactor); | |
97 | ||
98 | // Helper function to add a new timer queue. | |
99 | BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue); | |
100 | ||
101 | // Helper function to remove a timer queue. | |
102 | BOOST_ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue); | |
103 | ||
b32b8144 FG |
104 | // The io_context implementation used to post completions. |
105 | io_context_impl& io_context_; | |
7c673cae FG |
106 | |
107 | // Mutex used to protect internal variables. | |
108 | boost::asio::detail::mutex mutex_; | |
109 | ||
110 | // Event used to wake up background thread. | |
111 | boost::asio::detail::event event_; | |
112 | ||
113 | // The timer queues. | |
114 | timer_queue_set timer_queues_; | |
115 | ||
116 | // The background thread that is waiting for timers to expire. | |
117 | boost::asio::detail::thread* thread_; | |
118 | ||
119 | // Does the background thread need to stop. | |
120 | bool stop_thread_; | |
121 | ||
122 | // Whether the service has been shut down. | |
123 | bool shutdown_; | |
124 | }; | |
125 | ||
126 | } // namespace detail | |
127 | } // namespace asio | |
128 | } // namespace boost | |
129 | ||
130 | #include <boost/asio/detail/pop_options.hpp> | |
131 | ||
132 | #include <boost/asio/detail/impl/winrt_timer_scheduler.hpp> | |
133 | #if defined(BOOST_ASIO_HEADER_ONLY) | |
134 | # include <boost/asio/detail/impl/winrt_timer_scheduler.ipp> | |
135 | #endif // defined(BOOST_ASIO_HEADER_ONLY) | |
136 | ||
137 | #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) | |
138 | ||
139 | #endif // BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP |