Chris@16
|
1 //
|
Chris@16
|
2 // detail/impl/task_io_service.hpp
|
Chris@16
|
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@101
|
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP
|
Chris@16
|
12 #define BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/addressof.hpp>
|
Chris@16
|
19 #include <boost/asio/detail/completion_handler.hpp>
|
Chris@16
|
20 #include <boost/asio/detail/fenced_block.hpp>
|
Chris@16
|
21 #include <boost/asio/detail/handler_alloc_helpers.hpp>
|
Chris@16
|
22 #include <boost/asio/detail/handler_cont_helpers.hpp>
|
Chris@16
|
23 #include <boost/asio/detail/handler_invoke_helpers.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 namespace boost {
|
Chris@16
|
28 namespace asio {
|
Chris@16
|
29 namespace detail {
|
Chris@16
|
30
|
Chris@16
|
31 template <typename Handler>
|
Chris@16
|
32 void task_io_service::dispatch(Handler& handler)
|
Chris@16
|
33 {
|
Chris@16
|
34 if (thread_call_stack::contains(this))
|
Chris@16
|
35 {
|
Chris@16
|
36 fenced_block b(fenced_block::full);
|
Chris@16
|
37 boost_asio_handler_invoke_helpers::invoke(handler, handler);
|
Chris@16
|
38 }
|
Chris@16
|
39 else
|
Chris@16
|
40 {
|
Chris@16
|
41 // Allocate and construct an operation to wrap the handler.
|
Chris@16
|
42 typedef completion_handler<Handler> op;
|
Chris@16
|
43 typename op::ptr p = { boost::asio::detail::addressof(handler),
|
Chris@16
|
44 boost_asio_handler_alloc_helpers::allocate(
|
Chris@16
|
45 sizeof(op), handler), 0 };
|
Chris@16
|
46 p.p = new (p.v) op(handler);
|
Chris@16
|
47
|
Chris@16
|
48 BOOST_ASIO_HANDLER_CREATION((p.p, "io_service", this, "dispatch"));
|
Chris@16
|
49
|
Chris@16
|
50 do_dispatch(p.p);
|
Chris@16
|
51 p.v = p.p = 0;
|
Chris@16
|
52 }
|
Chris@16
|
53 }
|
Chris@16
|
54
|
Chris@16
|
55 template <typename Handler>
|
Chris@16
|
56 void task_io_service::post(Handler& handler)
|
Chris@16
|
57 {
|
Chris@16
|
58 bool is_continuation =
|
Chris@16
|
59 boost_asio_handler_cont_helpers::is_continuation(handler);
|
Chris@16
|
60
|
Chris@16
|
61 // Allocate and construct an operation to wrap the handler.
|
Chris@16
|
62 typedef completion_handler<Handler> op;
|
Chris@16
|
63 typename op::ptr p = { boost::asio::detail::addressof(handler),
|
Chris@16
|
64 boost_asio_handler_alloc_helpers::allocate(
|
Chris@16
|
65 sizeof(op), handler), 0 };
|
Chris@16
|
66 p.p = new (p.v) op(handler);
|
Chris@16
|
67
|
Chris@16
|
68 BOOST_ASIO_HANDLER_CREATION((p.p, "io_service", this, "post"));
|
Chris@16
|
69
|
Chris@16
|
70 post_immediate_completion(p.p, is_continuation);
|
Chris@16
|
71 p.v = p.p = 0;
|
Chris@16
|
72 }
|
Chris@16
|
73
|
Chris@16
|
74 } // namespace detail
|
Chris@16
|
75 } // namespace asio
|
Chris@16
|
76 } // namespace boost
|
Chris@16
|
77
|
Chris@16
|
78 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
79
|
Chris@16
|
80 #endif // BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP
|