Chris@16: // Chris@16: // detail/winrt_timer_scheduler.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP Chris@16: #define BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HAS_IOCP) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HAS_IOCP) Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace detail { Chris@16: Chris@16: class winrt_timer_scheduler Chris@16: : public boost::asio::detail::service_base Chris@16: { Chris@16: public: Chris@16: // Constructor. Chris@16: BOOST_ASIO_DECL winrt_timer_scheduler(boost::asio::io_service& io_service); Chris@16: Chris@16: // Destructor. Chris@16: BOOST_ASIO_DECL ~winrt_timer_scheduler(); Chris@16: Chris@16: // Destroy all user-defined handler objects owned by the service. Chris@16: BOOST_ASIO_DECL void shutdown_service(); Chris@16: Chris@16: // Recreate internal descriptors following a fork. Chris@16: BOOST_ASIO_DECL void fork_service( Chris@16: boost::asio::io_service::fork_event fork_ev); Chris@16: Chris@16: // Initialise the task. No effect as this class uses its own thread. Chris@16: BOOST_ASIO_DECL void init_task(); Chris@16: Chris@16: // Add a new timer queue to the reactor. Chris@16: template Chris@16: void add_timer_queue(timer_queue& queue); Chris@16: Chris@16: // Remove a timer queue from the reactor. Chris@16: template Chris@16: void remove_timer_queue(timer_queue& queue); Chris@16: Chris@16: // Schedule a new operation in the given timer queue to expire at the Chris@16: // specified absolute time. Chris@16: template Chris@16: void schedule_timer(timer_queue& queue, Chris@16: const typename Time_Traits::time_type& time, Chris@16: typename timer_queue::per_timer_data& timer, wait_op* op); Chris@16: Chris@16: // Cancel the timer operations associated with the given token. Returns the Chris@16: // number of operations that have been posted or dispatched. Chris@16: template Chris@16: std::size_t cancel_timer(timer_queue& queue, Chris@16: typename timer_queue::per_timer_data& timer, Chris@16: std::size_t max_cancelled = (std::numeric_limits::max)()); Chris@16: Chris@16: private: Chris@16: // Run the select loop in the thread. Chris@16: BOOST_ASIO_DECL void run_thread(); Chris@16: Chris@16: // Entry point for the select loop thread. Chris@16: BOOST_ASIO_DECL static void call_run_thread(winrt_timer_scheduler* reactor); Chris@16: Chris@16: // Helper function to add a new timer queue. Chris@16: BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue); Chris@16: Chris@16: // Helper function to remove a timer queue. Chris@16: BOOST_ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue); Chris@16: Chris@16: // The io_service implementation used to post completions. Chris@16: io_service_impl& io_service_; Chris@16: Chris@16: // Mutex used to protect internal variables. Chris@16: boost::asio::detail::mutex mutex_; Chris@16: Chris@16: // Event used to wake up background thread. Chris@16: boost::asio::detail::event event_; Chris@16: Chris@16: // The timer queues. Chris@16: timer_queue_set timer_queues_; Chris@16: Chris@16: // The background thread that is waiting for timers to expire. Chris@16: boost::asio::detail::thread* thread_; Chris@16: Chris@16: // Does the background thread need to stop. Chris@16: bool stop_thread_; Chris@16: Chris@16: // Whether the service has been shut down. Chris@16: bool shutdown_; Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP