File indexing completed on 2026-09-04 08:41:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_IPP
0012 #define BOOST_ASIO_DETAIL_IMPL_WINRT_TIMER_SCHEDULER_IPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
0021
0022 #include <boost/asio/detail/bind_handler.hpp>
0023 #include <boost/asio/detail/winrt_timer_scheduler.hpp>
0024
0025 #include <boost/asio/detail/push_options.hpp>
0026
0027 namespace boost {
0028 namespace asio {
0029 namespace detail {
0030
0031 winrt_timer_scheduler::winrt_timer_scheduler(execution_context& context)
0032 : execution_context_service_base<winrt_timer_scheduler>(context),
0033 scheduler_(use_service<scheduler_impl>(context)),
0034 mutex_(),
0035 event_(),
0036 timer_queues_(),
0037 thread_(),
0038 stop_thread_(false),
0039 shutdown_(false)
0040 {
0041 thread_ = thread(bind_handler(&winrt_timer_scheduler::call_run_thread, this));
0042 }
0043
0044 winrt_timer_scheduler::~winrt_timer_scheduler()
0045 {
0046 shutdown();
0047 }
0048
0049 void winrt_timer_scheduler::shutdown()
0050 {
0051 boost::asio::detail::mutex::scoped_lock lock(mutex_);
0052 shutdown_ = true;
0053 stop_thread_ = true;
0054 event_.signal(lock);
0055 lock.unlock();
0056 thread_.join();
0057
0058 op_queue<operation> ops;
0059 timer_queues_.get_all_timers(ops);
0060 scheduler_.abandon_operations(ops);
0061 }
0062
0063 void winrt_timer_scheduler::notify_fork(execution_context::fork_event)
0064 {
0065 }
0066
0067 void winrt_timer_scheduler::init_task()
0068 {
0069 }
0070
0071 void winrt_timer_scheduler::run_thread()
0072 {
0073 boost::asio::detail::mutex::scoped_lock lock(mutex_);
0074 while (!stop_thread_)
0075 {
0076 const long max_wait_duration = 5 * 60 * 1000000;
0077 long wait_duration = timer_queues_.wait_duration_usec(max_wait_duration);
0078 event_.wait_for_usec(lock, wait_duration);
0079 event_.clear(lock);
0080 op_queue<operation> ops;
0081 timer_queues_.get_ready_timers(ops);
0082 if (!ops.empty())
0083 {
0084 lock.unlock();
0085 scheduler_.post_deferred_completions(ops);
0086 lock.lock();
0087 }
0088 }
0089 }
0090
0091 void winrt_timer_scheduler::call_run_thread(winrt_timer_scheduler* scheduler)
0092 {
0093 scheduler->run_thread();
0094 }
0095
0096 void winrt_timer_scheduler::do_add_timer_queue(timer_queue_base& queue)
0097 {
0098 mutex::scoped_lock lock(mutex_);
0099 timer_queues_.insert(&queue);
0100 }
0101
0102 void winrt_timer_scheduler::do_remove_timer_queue(timer_queue_base& queue)
0103 {
0104 mutex::scoped_lock lock(mutex_);
0105 timer_queues_.erase(&queue);
0106 }
0107
0108 }
0109 }
0110 }
0111
0112 #include <boost/asio/detail/pop_options.hpp>
0113
0114 #endif
0115
0116 #endif