]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/detail/work_dispatcher.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / detail / work_dispatcher.hpp
CommitLineData
b32b8144
FG
1//
2// detail/work_dispatcher.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
92f5a8d4 5// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
b32b8144
FG
6//
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)
9//
10
11#ifndef BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP
12#define BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
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>
22
23#include <boost/asio/detail/push_options.hpp>
24
25namespace boost {
26namespace asio {
27namespace detail {
28
29template <typename Handler>
30class work_dispatcher
31{
32public:
92f5a8d4
TL
33 template <typename CompletionHandler>
34 explicit work_dispatcher(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler)
b32b8144 35 : work_((get_associated_executor)(handler)),
92f5a8d4 36 handler_(BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler))
b32b8144
FG
37 {
38 }
39
40#if defined(BOOST_ASIO_HAS_MOVE)
41 work_dispatcher(const work_dispatcher& other)
42 : work_(other.work_),
43 handler_(other.handler_)
44 {
45 }
46
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_))
51 {
52 }
53#endif // defined(BOOST_ASIO_HAS_MOVE)
54
55 void operator()()
56 {
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);
61 work_.reset();
62 }
63
64private:
65 executor_work_guard<typename associated_executor<Handler>::type> work_;
66 Handler handler_;
67};
68
69} // namespace detail
70} // namespace asio
71} // namespace boost
72
73#include <boost/asio/detail/pop_options.hpp>
74
75#endif // BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP