Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/asio/detail/impl/strand_service.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // detail/impl/strand_service.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_IMPL_STRAND_SERVICE_HPP
0012 #define BOOST_ASIO_DETAIL_IMPL_STRAND_SERVICE_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/completion_handler.hpp>
0019 #include <boost/asio/detail/fenced_block.hpp>
0020 #include <boost/asio/detail/handler_alloc_helpers.hpp>
0021 #include <boost/asio/detail/memory.hpp>
0022 
0023 #include <boost/asio/detail/push_options.hpp>
0024 
0025 namespace boost {
0026 namespace asio {
0027 namespace detail {
0028 
0029 inline strand_service::strand_impl::strand_impl()
0030   : operation(&strand_service::do_complete),
0031     locked_(false)
0032 {
0033 }
0034 
0035 template <typename Handler>
0036 void strand_service::dispatch(strand_service::implementation_type& impl,
0037     Handler& handler)
0038 {
0039   // If we are already in the strand then the handler can run immediately.
0040   if (running_in_this_thread(impl))
0041   {
0042     fenced_block b(fenced_block::full);
0043     static_cast<Handler&&>(handler)();
0044     return;
0045   }
0046 
0047   // Allocate and construct an operation to wrap the handler.
0048   typedef completion_handler<Handler, io_context::executor_type> op;
0049   typename op::ptr p = { boost::asio::detail::addressof(handler),
0050     op::ptr::allocate(handler), 0 };
0051   p.p = new (p.v) op(handler, io_context_.get_executor());
0052 
0053   BOOST_ASIO_HANDLER_CREATION((this->context(),
0054         *p.p, "strand", impl, 0, "dispatch"));
0055 
0056   operation* o = p.p;
0057   p.v = p.p = 0;
0058   do_dispatch(impl, o);
0059 }
0060 
0061 // Request the io_context to invoke the given handler and return immediately.
0062 template <typename Handler>
0063 void strand_service::post(strand_service::implementation_type& impl,
0064     Handler& handler)
0065 {
0066   bool is_continuation =
0067     boost_asio_handler_cont_helpers::is_continuation(handler);
0068 
0069   // Allocate and construct an operation to wrap the handler.
0070   typedef completion_handler<Handler, io_context::executor_type> op;
0071   typename op::ptr p = { boost::asio::detail::addressof(handler),
0072     op::ptr::allocate(handler), 0 };
0073   p.p = new (p.v) op(handler, io_context_.get_executor());
0074 
0075   BOOST_ASIO_HANDLER_CREATION((this->context(),
0076         *p.p, "strand", impl, 0, "post"));
0077 
0078   do_post(impl, p.p, is_continuation);
0079   p.v = p.p = 0;
0080 }
0081 
0082 } // namespace detail
0083 } // namespace asio
0084 } // namespace boost
0085 
0086 #include <boost/asio/detail/pop_options.hpp>
0087 
0088 #endif // BOOST_ASIO_DETAIL_IMPL_STRAND_SERVICE_HPP