2 // detail/work_dispatcher.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2019 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_WORK_DISPATCHER_HPP
12 #define BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/associated_executor.hpp>
20 #include <boost/asio/associated_allocator.hpp>
21 #include <boost/asio/executor_work_guard.hpp>
23 #include <boost/asio/detail/push_options.hpp>
29 template <typename Handler>
33 template <typename CompletionHandler>
34 explicit work_dispatcher(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler)
35 : work_((get_associated_executor)(handler)),
36 handler_(BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler))
40 #if defined(BOOST_ASIO_HAS_MOVE)
41 work_dispatcher(const work_dispatcher& other)
43 handler_(other.handler_)
47 work_dispatcher(work_dispatcher&& other)
48 : work_(BOOST_ASIO_MOVE_CAST(executor_work_guard<
49 typename associated_executor<Handler>::type>)(other.work_)),
50 handler_(BOOST_ASIO_MOVE_CAST(Handler)(other.handler_))
53 #endif // defined(BOOST_ASIO_HAS_MOVE)
57 typename associated_allocator<Handler>::type alloc(
58 (get_associated_allocator)(handler_));
59 work_.get_executor().dispatch(
60 BOOST_ASIO_MOVE_CAST(Handler)(handler_), alloc);
65 executor_work_guard<typename associated_executor<Handler>::type> work_;
73 #include <boost/asio/detail/pop_options.hpp>
75 #endif // BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP