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