]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/impl/defer.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / impl / defer.hpp
1 //
2 // impl/defer.hpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2019 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_IMPL_DEFER_HPP
12 #define BOOST_ASIO_IMPL_DEFER_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_allocator.hpp>
20 #include <boost/asio/associated_executor.hpp>
21 #include <boost/asio/detail/work_dispatcher.hpp>
22
23 #include <boost/asio/detail/push_options.hpp>
24
25 namespace boost {
26 namespace asio {
27 namespace detail {
28
29 class initiate_defer
30 {
31 public:
32 template <typename CompletionHandler>
33 void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) const
34 {
35 typedef typename decay<CompletionHandler>::type DecayedHandler;
36
37 typename associated_executor<DecayedHandler>::type ex(
38 (get_associated_executor)(handler));
39
40 typename associated_allocator<DecayedHandler>::type alloc(
41 (get_associated_allocator)(handler));
42
43 ex.defer(BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler), alloc);
44 }
45 };
46
47 template <typename Executor>
48 class initiate_defer_with_executor
49 {
50 public:
51 typedef Executor executor_type;
52
53 explicit initiate_defer_with_executor(const Executor& ex)
54 : ex_(ex)
55 {
56 }
57
58 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
59 {
60 return ex_;
61 }
62
63 template <typename CompletionHandler>
64 void operator()(BOOST_ASIO_MOVE_ARG(CompletionHandler) handler) const
65 {
66 typedef typename decay<CompletionHandler>::type DecayedHandler;
67
68 typename associated_allocator<DecayedHandler>::type alloc(
69 (get_associated_allocator)(handler));
70
71 ex_.defer(detail::work_dispatcher<DecayedHandler>(
72 BOOST_ASIO_MOVE_CAST(CompletionHandler)(handler)), alloc);
73 }
74
75 private:
76 Executor ex_;
77 };
78
79 } // namespace detail
80
81 template <BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
82 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
83 BOOST_ASIO_MOVE_ARG(CompletionToken) token)
84 {
85 return async_initiate<CompletionToken, void()>(
86 detail::initiate_defer(), token);
87 }
88
89 template <typename Executor,
90 BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
91 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
92 const Executor& ex, BOOST_ASIO_MOVE_ARG(CompletionToken) token,
93 typename enable_if<is_executor<Executor>::value>::type*)
94 {
95 return async_initiate<CompletionToken, void()>(
96 detail::initiate_defer_with_executor<Executor>(ex), token);
97 }
98
99 template <typename ExecutionContext,
100 BOOST_ASIO_COMPLETION_TOKEN_FOR(void()) CompletionToken>
101 inline BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, void()) defer(
102 ExecutionContext& ctx, BOOST_ASIO_MOVE_ARG(CompletionToken) token,
103 typename enable_if<is_convertible<
104 ExecutionContext&, execution_context&>::value>::type*)
105 {
106 return (defer)(ctx.get_executor(),
107 BOOST_ASIO_MOVE_CAST(CompletionToken)(token));
108 }
109
110 } // namespace asio
111 } // namespace boost
112
113 #include <boost/asio/detail/pop_options.hpp>
114
115 #endif // BOOST_ASIO_IMPL_DEFER_HPP