2 // detail/work_dispatcher.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 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 work_dispatcher(Handler& handler)
34 : work_((get_associated_executor)(handler)),
35 handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
39 #if defined(BOOST_ASIO_HAS_MOVE)
40 work_dispatcher(const work_dispatcher& other)
42 handler_(other.handler_)
46 work_dispatcher(work_dispatcher&& other)
47 : work_(BOOST_ASIO_MOVE_CAST(executor_work_guard<
48 typename associated_executor<Handler>::type>)(other.work_)),
49 handler_(BOOST_ASIO_MOVE_CAST(Handler)(other.handler_))
52 #endif // defined(BOOST_ASIO_HAS_MOVE)
56 typename associated_allocator<Handler>::type alloc(
57 (get_associated_allocator)(handler_));
58 work_.get_executor().dispatch(
59 BOOST_ASIO_MOVE_CAST(Handler)(handler_), alloc);
64 executor_work_guard<typename associated_executor<Handler>::type> work_;
72 #include <boost/asio/detail/pop_options.hpp>
74 #endif // BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP