2 // detail/impl/winrt_timer_scheduler.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_HPP
12 #define BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
22 #include <boost/asio/detail/push_options.hpp>
28 template <typename Time_Traits>
29 void winrt_timer_scheduler::add_timer_queue(timer_queue<Time_Traits>& queue)
31 do_add_timer_queue(queue);
34 // Remove a timer queue from the reactor.
35 template <typename Time_Traits>
36 void winrt_timer_scheduler::remove_timer_queue(timer_queue<Time_Traits>& queue)
38 do_remove_timer_queue(queue);
41 template <typename Time_Traits>
42 void winrt_timer_scheduler::schedule_timer(timer_queue<Time_Traits>& queue,
43 const typename Time_Traits::time_type& time,
44 typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
46 boost::asio::detail::mutex::scoped_lock lock(mutex_);
50 io_context_.post_immediate_completion(op, false);
54 bool earliest = queue.enqueue_timer(time, timer, op);
55 io_context_.work_started();
60 template <typename Time_Traits>
61 std::size_t winrt_timer_scheduler::cancel_timer(timer_queue<Time_Traits>& queue,
62 typename timer_queue<Time_Traits>::per_timer_data& timer,
63 std::size_t max_cancelled)
65 boost::asio::detail::mutex::scoped_lock lock(mutex_);
66 op_queue<operation> ops;
67 std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
69 io_context_.post_deferred_completions(ops);
73 template <typename Time_Traits>
74 void winrt_timer_scheduler::move_timer(timer_queue<Time_Traits>& queue,
75 typename timer_queue<Time_Traits>::per_timer_data& to,
76 typename timer_queue<Time_Traits>::per_timer_data& from)
78 boost::asio::detail::mutex::scoped_lock lock(mutex_);
79 op_queue<operation> ops;
80 queue.cancel_timer(to, ops);
81 queue.move_timer(to, from);
83 scheduler_.post_deferred_completions(ops);
90 #include <boost/asio/detail/pop_options.hpp>
92 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
94 #endif // BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_HPP