Chris@16: // Chris@16: // detail/impl/task_io_service.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP Chris@16: #define BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: void task_io_service::dispatch(Handler& handler) Chris@16: { Chris@16: if (thread_call_stack::contains(this)) Chris@16: { Chris@16: fenced_block b(fenced_block::full); Chris@16: boost_asio_handler_invoke_helpers::invoke(handler, handler); Chris@16: } Chris@16: else Chris@16: { Chris@16: // Allocate and construct an operation to wrap the handler. Chris@16: typedef completion_handler op; Chris@16: typename op::ptr p = { boost::asio::detail::addressof(handler), Chris@16: boost_asio_handler_alloc_helpers::allocate( Chris@16: sizeof(op), handler), 0 }; Chris@16: p.p = new (p.v) op(handler); Chris@16: Chris@16: BOOST_ASIO_HANDLER_CREATION((p.p, "io_service", this, "dispatch")); Chris@16: Chris@16: do_dispatch(p.p); Chris@16: p.v = p.p = 0; Chris@16: } Chris@16: } Chris@16: Chris@16: template Chris@16: void task_io_service::post(Handler& handler) Chris@16: { Chris@16: bool is_continuation = Chris@16: boost_asio_handler_cont_helpers::is_continuation(handler); Chris@16: Chris@16: // Allocate and construct an operation to wrap the handler. Chris@16: typedef completion_handler op; Chris@16: typename op::ptr p = { boost::asio::detail::addressof(handler), Chris@16: boost_asio_handler_alloc_helpers::allocate( Chris@16: sizeof(op), handler), 0 }; Chris@16: p.p = new (p.v) op(handler); Chris@16: Chris@16: BOOST_ASIO_HANDLER_CREATION((p.p, "io_service", this, "post")); Chris@16: Chris@16: post_immediate_completion(p.p, is_continuation); Chris@16: p.v = p.p = 0; Chris@16: } Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_IMPL_TASK_IO_SERVICE_HPP