]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/handler_work.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / detail / handler_work.hpp
1 //
2 // detail/handler_work.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_HANDLER_WORK_HPP
12 #define BOOST_ASIO_DETAIL_HANDLER_WORK_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/detail/handler_invoke_helpers.hpp>
21
22 #include <boost/asio/detail/push_options.hpp>
23
24 namespace boost {
25 namespace asio {
26 namespace detail {
27
28 // A helper class template to allow completion handlers to be dispatched
29 // through either the new executors framework or the old invocaton hook. The
30 // primary template uses the new executors framework.
31 template <typename Handler, typename Executor
32 = typename associated_executor<Handler>::type>
33 class handler_work
34 {
35 public:
36 explicit handler_work(Handler& handler) BOOST_ASIO_NOEXCEPT
37 : executor_(associated_executor<Handler>::get(handler))
38 {
39 }
40
41 static void start(Handler& handler) BOOST_ASIO_NOEXCEPT
42 {
43 Executor ex(associated_executor<Handler>::get(handler));
44 ex.on_work_started();
45 }
46
47 ~handler_work()
48 {
49 executor_.on_work_finished();
50 }
51
52 template <typename Function>
53 void complete(Function& function, Handler& handler)
54 {
55 executor_.dispatch(BOOST_ASIO_MOVE_CAST(Function)(function),
56 associated_allocator<Handler>::get(handler));
57 }
58
59 private:
60 // Disallow copying and assignment.
61 handler_work(const handler_work&);
62 handler_work& operator=(const handler_work&);
63
64 typename associated_executor<Handler>::type executor_;
65 };
66
67 // This specialisation dispatches a handler through the old invocation hook.
68 // The specialisation is not strictly required for correctness, as the
69 // system_executor will dispatch through the hook anyway. However, by doing
70 // this we avoid an extra copy of the handler.
71 template <typename Handler>
72 class handler_work<Handler, system_executor>
73 {
74 public:
75 explicit handler_work(Handler&) BOOST_ASIO_NOEXCEPT {}
76 static void start(Handler&) BOOST_ASIO_NOEXCEPT {}
77 ~handler_work() {}
78
79 template <typename Function>
80 void complete(Function& function, Handler& handler)
81 {
82 boost_asio_handler_invoke_helpers::invoke(function, handler);
83 }
84
85 private:
86 // Disallow copying and assignment.
87 handler_work(const handler_work&);
88 handler_work& operator=(const handler_work&);
89 };
90
91 } // namespace detail
92 } // namespace asio
93 } // namespace boost
94
95 #include <boost/asio/detail/pop_options.hpp>
96
97 #endif // BOOST_ASIO_DETAIL_HANDLER_WORK_HPP