2 // detail/impl/task_io_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP
12 #define BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/addressof.hpp>
19 #include <boost/asio/detail/completion_handler.hpp>
20 #include <boost/asio/detail/fenced_block.hpp>
21 #include <boost/asio/detail/handler_alloc_helpers.hpp>
22 #include <boost/asio/detail/handler_cont_helpers.hpp>
23 #include <boost/asio/detail/handler_invoke_helpers.hpp>
25 #include <boost/asio/detail/push_options.hpp>
31 template <typename Handler>
32 void task_io_service::dispatch(Handler& handler)
34 if (thread_call_stack::contains(this))
36 fenced_block b(fenced_block::full);
37 boost_asio_handler_invoke_helpers::invoke(handler, handler);
41 // Allocate and construct an operation to wrap the handler.
42 typedef completion_handler<Handler> op;
43 typename op::ptr p = { boost::asio::detail::addressof(handler),
44 boost_asio_handler_alloc_helpers::allocate(
45 sizeof(op), handler), 0 };
46 p.p = new (p.v) op(handler);
48 BOOST_ASIO_HANDLER_CREATION((p.p, "io_service", this, "dispatch"));
55 template <typename Handler>
56 void task_io_service::post(Handler& handler)
58 bool is_continuation =
59 boost_asio_handler_cont_helpers::is_continuation(handler);
61 // Allocate and construct an operation to wrap the handler.
62 typedef completion_handler<Handler> op;
63 typename op::ptr p = { boost::asio::detail::addressof(handler),
64 boost_asio_handler_alloc_helpers::allocate(
65 sizeof(op), handler), 0 };
66 p.p = new (p.v) op(handler);
68 BOOST_ASIO_HANDLER_CREATION((p.p, "io_service", this, "post"));
70 post_immediate_completion(p.p, is_continuation);
78 #include <boost/asio/detail/pop_options.hpp>
80 #endif // BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP