Realistic 3D camera system
3D camera system components
win_iocp_io_service.hpp
Go to the documentation of this file.
1 //
2 // detail/impl/win_iocp_io_service.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_IMPL_WIN_IOCP_IO_SERVICE_HPP
12 #define ASIO_DETAIL_IMPL_WIN_IOCP_IO_SERVICE_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_HAS_IOCP)
21 
27 
29 
30 namespace asio {
31 namespace detail {
32 
33 template <typename Handler>
34 void win_iocp_io_service::dispatch(Handler& handler)
35 {
36  if (thread_call_stack::contains(this))
37  {
39  asio_handler_invoke_helpers::invoke(handler, handler);
40  }
41  else
42  {
43  // Allocate and construct an operation to wrap the handler.
44  typedef completion_handler<Handler> op;
45  typename op::ptr p = { asio::detail::addressof(handler),
47  sizeof(op), handler), 0 };
48  p.p = new (p.v) op(handler);
49 
50  ASIO_HANDLER_CREATION((p.p, "io_service", this, "dispatch"));
51 
52  post_immediate_completion(p.p, false);
53  p.v = p.p = 0;
54  }
55 }
56 
57 template <typename Handler>
58 void win_iocp_io_service::post(Handler& handler)
59 {
60  // Allocate and construct an operation to wrap the handler.
61  typedef completion_handler<Handler> op;
62  typename op::ptr p = { asio::detail::addressof(handler),
64  sizeof(op), handler), 0 };
65  p.p = new (p.v) op(handler);
66 
67  ASIO_HANDLER_CREATION((p.p, "io_service", this, "post"));
68 
69  post_immediate_completion(p.p, false);
70  p.v = p.p = 0;
71 }
72 
73 template <typename Time_Traits>
74 void win_iocp_io_service::add_timer_queue(
75  timer_queue<Time_Traits>& queue)
76 {
77  do_add_timer_queue(queue);
78 }
79 
80 template <typename Time_Traits>
81 void win_iocp_io_service::remove_timer_queue(
82  timer_queue<Time_Traits>& queue)
83 {
84  do_remove_timer_queue(queue);
85 }
86 
87 template <typename Time_Traits>
88 void win_iocp_io_service::schedule_timer(timer_queue<Time_Traits>& queue,
89  const typename Time_Traits::time_type& time,
90  typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op)
91 {
92  // If the service has been shut down we silently discard the timer.
93  if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
94  {
95  post_immediate_completion(op, false);
96  return;
97  }
98 
99  mutex::scoped_lock lock(dispatch_mutex_);
100 
101  bool earliest = queue.enqueue_timer(time, timer, op);
102  work_started();
103  if (earliest)
104  update_timeout();
105 }
106 
107 template <typename Time_Traits>
108 std::size_t win_iocp_io_service::cancel_timer(timer_queue<Time_Traits>& queue,
109  typename timer_queue<Time_Traits>::per_timer_data& timer,
110  std::size_t max_cancelled)
111 {
112  // If the service has been shut down we silently ignore the cancellation.
113  if (::InterlockedExchangeAdd(&shutdown_, 0) != 0)
114  return 0;
115 
116  mutex::scoped_lock lock(dispatch_mutex_);
117  op_queue<win_iocp_operation> ops;
118  std::size_t n = queue.cancel_timer(timer, ops, max_cancelled);
119  post_deferred_completions(ops);
120  return n;
121 }
122 
123 } // namespace detail
124 } // namespace asio
125 
127 
128 #endif // defined(ASIO_HAS_IOCP)
129 
130 #endif // ASIO_DETAIL_IMPL_WIN_IOCP_IO_SERVICE_HPP
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
null_fenced_block fenced_block
void invoke(Function &function, Context &context)
asio::detail::scoped_lock< null_mutex > scoped_lock
Definition: null_mutex.hpp:34
void * allocate(std::size_t s, Handler &h)
#define ASIO_HANDLER_CREATION(args)