• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // detail/impl/winrt_timer_scheduler.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2021 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 
11 #ifndef BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_HPP
12 #define BOOST_ASIO_DETAIL_IMPL_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 <boost/asio/detail/push_options.hpp>
23 
24 namespace boost {
25 namespace asio {
26 namespace detail {
27 
28 template <typename Time_Traits>
add_timer_queue(timer_queue<Time_Traits> & queue)29 void winrt_timer_scheduler::add_timer_queue(timer_queue<Time_Traits>& queue)
30 {
31   do_add_timer_queue(queue);
32 }
33 
34 // Remove a timer queue from the reactor.
35 template <typename Time_Traits>
remove_timer_queue(timer_queue<Time_Traits> & queue)36 void winrt_timer_scheduler::remove_timer_queue(timer_queue<Time_Traits>& queue)
37 {
38   do_remove_timer_queue(queue);
39 }
40 
41 template <typename Time_Traits>
schedule_timer(timer_queue<Time_Traits> & queue,const typename Time_Traits::time_type & time,typename timer_queue<Time_Traits>::per_timer_data & timer,wait_op * op)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)
45 {
46   boost::asio::detail::mutex::scoped_lock lock(mutex_);
47 
48   if (shutdown_)
49   {
50     scheduler_.post_immediate_completion(op, false);
51     return;
52   }
53 
54   bool earliest = queue.enqueue_timer(time, timer, op);
55   scheduler_.work_started();
56   if (earliest)
57     event_.signal(lock);
58 }
59 
60 template <typename Time_Traits>
cancel_timer(timer_queue<Time_Traits> & queue,typename timer_queue<Time_Traits>::per_timer_data & timer,std::size_t max_cancelled)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)
64 {
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);
68   lock.unlock();
69   scheduler_.post_deferred_completions(ops);
70   return n;
71 }
72 
73 template <typename Time_Traits>
move_timer(timer_queue<Time_Traits> & queue,typename timer_queue<Time_Traits>::per_timer_data & to,typename timer_queue<Time_Traits>::per_timer_data & from)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)
77 {
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);
82   lock.unlock();
83   scheduler_.post_deferred_completions(ops);
84 }
85 
86 } // namespace detail
87 } // namespace asio
88 } // namespace boost
89 
90 #include <boost/asio/detail/pop_options.hpp>
91 
92 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
93 
94 #endif // BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_HPP
95