]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/work_dispatcher.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / detail / work_dispatcher.hpp
1 //
2 // detail/work_dispatcher.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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
25 namespace boost {
26 namespace asio {
27 namespace detail {
28
29 template <typename Handler>
30 class work_dispatcher
31 {
32 public:
33 work_dispatcher(Handler& handler)
34 : work_((get_associated_executor)(handler)),
35 handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
36 {
37 }
38
39 #if defined(BOOST_ASIO_HAS_MOVE)
40 work_dispatcher(const work_dispatcher& other)
41 : work_(other.work_),
42 handler_(other.handler_)
43 {
44 }
45
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_))
50 {
51 }
52 #endif // defined(BOOST_ASIO_HAS_MOVE)
53
54 void operator()()
55 {
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);
60 work_.reset();
61 }
62
63 private:
64 executor_work_guard<typename associated_executor<Handler>::type> work_;
65 Handler handler_;
66 };
67
68 } // namespace detail
69 } // namespace asio
70 } // namespace boost
71
72 #include <boost/asio/detail/pop_options.hpp>
73
74 #endif // BOOST_ASIO_DETAIL_WORK_DISPATCHER_HPP