Realistic 3D camera system
3D camera system components
winrt_timer_scheduler.hpp
Go to the documentation of this file.
1 //
2 // detail/winrt_timer_scheduler.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 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 ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP
12 #define ASIO_DETAIL_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 "asio/detail/config.hpp"
19 
20 #if defined(ASIO_WINDOWS_RUNTIME)
21 
22 #include <cstddef>
23 #include "asio/detail/event.hpp"
24 #include "asio/detail/limits.hpp"
25 #include "asio/detail/mutex.hpp"
26 #include "asio/detail/op_queue.hpp"
27 #include "asio/detail/thread.hpp"
30 #include "asio/detail/wait_op.hpp"
31 #include "asio/io_service.hpp"
32 
33 #if defined(ASIO_HAS_IOCP)
34 # include "asio/detail/thread.hpp"
35 #endif // defined(ASIO_HAS_IOCP)
36 
38 
39 namespace asio {
40 namespace detail {
41 
42 class winrt_timer_scheduler
43  : public asio::detail::service_base<winrt_timer_scheduler>
44 {
45 public:
46  // Constructor.
47  ASIO_DECL winrt_timer_scheduler(asio::io_service& io_service);
48 
49  // Destructor.
50  ASIO_DECL ~winrt_timer_scheduler();
51 
52  // Destroy all user-defined handler objects owned by the service.
53  ASIO_DECL void shutdown_service();
54 
55  // Recreate internal descriptors following a fork.
56  ASIO_DECL void fork_service(
58 
59  // Initialise the task. No effect as this class uses its own thread.
60  ASIO_DECL void init_task();
61 
62  // Add a new timer queue to the reactor.
63  template <typename Time_Traits>
64  void add_timer_queue(timer_queue<Time_Traits>& queue);
65 
66  // Remove a timer queue from the reactor.
67  template <typename Time_Traits>
68  void remove_timer_queue(timer_queue<Time_Traits>& queue);
69 
70  // Schedule a new operation in the given timer queue to expire at the
71  // specified absolute time.
72  template <typename Time_Traits>
73  void schedule_timer(timer_queue<Time_Traits>& queue,
74  const typename Time_Traits::time_type& time,
75  typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
76 
77  // Cancel the timer operations associated with the given token. Returns the
78  // number of operations that have been posted or dispatched.
79  template <typename Time_Traits>
80  std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
81  typename timer_queue<Time_Traits>::per_timer_data& timer,
82  std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
83 
84 private:
85  // Run the select loop in the thread.
86  ASIO_DECL void run_thread();
87 
88  // Entry point for the select loop thread.
89  ASIO_DECL static void call_run_thread(winrt_timer_scheduler* reactor);
90 
91  // Helper function to add a new timer queue.
92  ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
93 
94  // Helper function to remove a timer queue.
95  ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
96 
97  // The io_service implementation used to post completions.
98  io_service_impl& io_service_;
99 
100  // Mutex used to protect internal variables.
101  asio::detail::mutex mutex_;
102 
103  // Event used to wake up background thread.
104  asio::detail::event event_;
105 
106  // The timer queues.
107  timer_queue_set timer_queues_;
108 
109  // The background thread that is waiting for timers to expire.
110  asio::detail::thread* thread_;
111 
112  // Does the background thread need to stop.
113  bool stop_thread_;
114 
115  // Whether the service has been shut down.
116  bool shutdown_;
117 };
118 
119 } // namespace detail
120 } // namespace asio
121 
123 
125 #if defined(ASIO_HEADER_ONLY)
127 #endif // defined(ASIO_HEADER_ONLY)
128 
129 #endif // defined(ASIO_WINDOWS_RUNTIME)
130 
131 #endif // ASIO_DETAIL_WINRT_TIMER_SCHEDULER_HPP
Provides core I/O functionality.
Definition: io_service.hpp:184
class task_io_service io_service_impl
Definition: io_service.hpp:48
class select_reactor reactor
Definition: reactor_fwd.hpp:34
fork_event
Fork-related event notifications.
Definition: io_service.hpp:501
#define ASIO_DECL
Definition: config.hpp:43