2 // detail/impl/winrt_timer_scheduler.ipp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 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_IPP
12 #define BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_IPP
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/bind_handler.hpp>
23 #include <boost/asio/detail/winrt_timer_scheduler.hpp>
25 #include <boost/asio/detail/push_options.hpp>
31 winrt_timer_scheduler::winrt_timer_scheduler(
32 boost::asio::io_service& io_service)
33 : boost::asio::detail::service_base<winrt_timer_scheduler>(io_service),
34 io_service_(use_service<io_service_impl>(io_service)),
42 thread_ = new boost::asio::detail::thread(
43 bind_handler(&winrt_timer_scheduler::call_run_thread, this));
46 winrt_timer_scheduler::~winrt_timer_scheduler()
51 void winrt_timer_scheduler::shutdown_service()
53 boost::asio::detail::mutex::scoped_lock lock(mutex_);
66 op_queue<operation> ops;
67 timer_queues_.get_all_timers(ops);
68 io_service_.abandon_operations(ops);
71 void winrt_timer_scheduler::fork_service(boost::asio::io_service::fork_event)
75 void winrt_timer_scheduler::init_task()
79 void winrt_timer_scheduler::run_thread()
81 boost::asio::detail::mutex::scoped_lock lock(mutex_);
84 const long max_wait_duration = 5 * 60 * 1000000;
85 long wait_duration = timer_queues_.wait_duration_usec(max_wait_duration);
86 event_.wait_for_usec(lock, wait_duration);
88 op_queue<operation> ops;
89 timer_queues_.get_ready_timers(ops);
93 io_service_.post_deferred_completions(ops);
99 void winrt_timer_scheduler::call_run_thread(winrt_timer_scheduler* scheduler)
101 scheduler->run_thread();
104 void winrt_timer_scheduler::do_add_timer_queue(timer_queue_base& queue)
106 mutex::scoped_lock lock(mutex_);
107 timer_queues_.insert(&queue);
110 void winrt_timer_scheduler::do_remove_timer_queue(timer_queue_base& queue)
112 mutex::scoped_lock lock(mutex_);
113 timer_queues_.erase(&queue);
116 } // namespace detail
120 #include <boost/asio/detail/pop_options.hpp>
122 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
124 #endif // BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_IPP