]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/handler_tracking.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / detail / handler_tracking.hpp
1 //
2 // detail/handler_tracking.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_TRACKING_HPP
12 #define BOOST_ASIO_DETAIL_HANDLER_TRACKING_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
20 namespace boost {
21 namespace asio {
22
23 class execution_context;
24
25 } // namespace asio
26 } // namespace boost
27
28 #if defined(BOOST_ASIO_CUSTOM_HANDLER_TRACKING)
29 # include BOOST_ASIO_CUSTOM_HANDLER_TRACKING
30 #elif defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
31 # include <boost/system/error_code.hpp>
32 # include <boost/asio/detail/cstdint.hpp>
33 # include <boost/asio/detail/static_mutex.hpp>
34 # include <boost/asio/detail/tss_ptr.hpp>
35 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
36
37 #include <boost/asio/detail/push_options.hpp>
38
39 namespace boost {
40 namespace asio {
41 namespace detail {
42
43 #if defined(BOOST_ASIO_CUSTOM_HANDLER_TRACKING)
44
45 // The user-specified header must define the following macros:
46 // - BOOST_ASIO_INHERIT_TRACKED_HANDLER
47 // - BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
48 // - BOOST_ASIO_HANDLER_TRACKING_INIT
49 // - BOOST_ASIO_HANDLER_CREATION(args)
50 // - BOOST_ASIO_HANDLER_COMPLETION(args)
51 // - BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args)
52 // - BOOST_ASIO_HANDLER_INVOCATION_END
53 // - BOOST_ASIO_HANDLER_OPERATION(args)
54 // - BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args)
55 // - BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args)
56 // - BOOST_ASIO_HANDLER_REACTOR_READ_EVENT
57 // - BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT
58 // - BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT
59 // - BOOST_ASIO_HANDLER_REACTOR_EVENTS(args)
60 // - BOOST_ASIO_HANDLER_REACTOR_OPERATION(args)
61
62 # if !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
63 # define BOOST_ASIO_ENABLE_HANDLER_TRACKING 1
64 # endif /// !defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
65
66 #elif defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
67
68 class handler_tracking
69 {
70 public:
71 class completion;
72
73 // Base class for objects containing tracked handlers.
74 class tracked_handler
75 {
76 private:
77 // Only the handler_tracking class will have access to the id.
78 friend class handler_tracking;
79 friend class completion;
80 uint64_t id_;
81
82 protected:
83 // Constructor initialises with no id.
84 tracked_handler() : id_(0) {}
85
86 // Prevent deletion through this type.
87 ~tracked_handler() {}
88 };
89
90 // Initialise the tracking system.
91 BOOST_ASIO_DECL static void init();
92
93 // Record the creation of a tracked handler.
94 BOOST_ASIO_DECL static void creation(
95 execution_context& context, tracked_handler& h,
96 const char* object_type, void* object,
97 uintmax_t native_handle, const char* op_name);
98
99 class completion
100 {
101 public:
102 // Constructor records that handler is to be invoked with no arguments.
103 BOOST_ASIO_DECL explicit completion(const tracked_handler& h);
104
105 // Destructor records only when an exception is thrown from the handler, or
106 // if the memory is being freed without the handler having been invoked.
107 BOOST_ASIO_DECL ~completion();
108
109 // Records that handler is to be invoked with no arguments.
110 BOOST_ASIO_DECL void invocation_begin();
111
112 // Records that handler is to be invoked with one arguments.
113 BOOST_ASIO_DECL void invocation_begin(const boost::system::error_code& ec);
114
115 // Constructor records that handler is to be invoked with two arguments.
116 BOOST_ASIO_DECL void invocation_begin(
117 const boost::system::error_code& ec, std::size_t bytes_transferred);
118
119 // Constructor records that handler is to be invoked with two arguments.
120 BOOST_ASIO_DECL void invocation_begin(
121 const boost::system::error_code& ec, int signal_number);
122
123 // Constructor records that handler is to be invoked with two arguments.
124 BOOST_ASIO_DECL void invocation_begin(
125 const boost::system::error_code& ec, const char* arg);
126
127 // Record that handler invocation has ended.
128 BOOST_ASIO_DECL void invocation_end();
129
130 private:
131 friend class handler_tracking;
132 uint64_t id_;
133 bool invoked_;
134 completion* next_;
135 };
136
137 // Record an operation that is not directly associated with a handler.
138 BOOST_ASIO_DECL static void operation(execution_context& context,
139 const char* object_type, void* object,
140 uintmax_t native_handle, const char* op_name);
141
142 // Record that a descriptor has been registered with the reactor.
143 BOOST_ASIO_DECL static void reactor_registration(execution_context& context,
144 uintmax_t native_handle, uintmax_t registration);
145
146 // Record that a descriptor has been deregistered from the reactor.
147 BOOST_ASIO_DECL static void reactor_deregistration(execution_context& context,
148 uintmax_t native_handle, uintmax_t registration);
149
150 // Record a reactor-based operation that is associated with a handler.
151 BOOST_ASIO_DECL static void reactor_events(execution_context& context,
152 uintmax_t registration, unsigned events);
153
154 // Record a reactor-based operation that is associated with a handler.
155 BOOST_ASIO_DECL static void reactor_operation(
156 const tracked_handler& h, const char* op_name,
157 const boost::system::error_code& ec);
158
159 // Record a reactor-based operation that is associated with a handler.
160 BOOST_ASIO_DECL static void reactor_operation(
161 const tracked_handler& h, const char* op_name,
162 const boost::system::error_code& ec, std::size_t bytes_transferred);
163
164 // Write a line of output.
165 BOOST_ASIO_DECL static void write_line(const char* format, ...);
166
167 private:
168 struct tracking_state;
169 BOOST_ASIO_DECL static tracking_state* get_state();
170 };
171
172 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER \
173 : public boost::asio::detail::handler_tracking::tracked_handler
174
175 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER \
176 , public boost::asio::detail::handler_tracking::tracked_handler
177
178 # define BOOST_ASIO_HANDLER_TRACKING_INIT \
179 boost::asio::detail::handler_tracking::init()
180
181 # define BOOST_ASIO_HANDLER_CREATION(args) \
182 boost::asio::detail::handler_tracking::creation args
183
184 # define BOOST_ASIO_HANDLER_COMPLETION(args) \
185 boost::asio::detail::handler_tracking::completion tracked_completion args
186
187 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) \
188 tracked_completion.invocation_begin args
189
190 # define BOOST_ASIO_HANDLER_INVOCATION_END \
191 tracked_completion.invocation_end()
192
193 # define BOOST_ASIO_HANDLER_OPERATION(args) \
194 boost::asio::detail::handler_tracking::operation args
195
196 # define BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) \
197 boost::asio::detail::handler_tracking::reactor_registration args
198
199 # define BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) \
200 boost::asio::detail::handler_tracking::reactor_deregistration args
201
202 # define BOOST_ASIO_HANDLER_REACTOR_READ_EVENT 1
203 # define BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT 2
204 # define BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT 4
205
206 # define BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) \
207 boost::asio::detail::handler_tracking::reactor_events args
208
209 # define BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) \
210 boost::asio::detail::handler_tracking::reactor_operation args
211
212 #else // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
213
214 # define BOOST_ASIO_INHERIT_TRACKED_HANDLER
215 # define BOOST_ASIO_ALSO_INHERIT_TRACKED_HANDLER
216 # define BOOST_ASIO_HANDLER_TRACKING_INIT (void)0
217 # define BOOST_ASIO_HANDLER_CREATION(args) (void)0
218 # define BOOST_ASIO_HANDLER_COMPLETION(args) (void)0
219 # define BOOST_ASIO_HANDLER_INVOCATION_BEGIN(args) (void)0
220 # define BOOST_ASIO_HANDLER_INVOCATION_END (void)0
221 # define BOOST_ASIO_HANDLER_OPERATION(args) (void)0
222 # define BOOST_ASIO_HANDLER_REACTOR_REGISTRATION(args) (void)0
223 # define BOOST_ASIO_HANDLER_REACTOR_DEREGISTRATION(args) (void)0
224 # define BOOST_ASIO_HANDLER_REACTOR_READ_EVENT 0
225 # define BOOST_ASIO_HANDLER_REACTOR_WRITE_EVENT 0
226 # define BOOST_ASIO_HANDLER_REACTOR_ERROR_EVENT 0
227 # define BOOST_ASIO_HANDLER_REACTOR_EVENTS(args) (void)0
228 # define BOOST_ASIO_HANDLER_REACTOR_OPERATION(args) (void)0
229
230 #endif // defined(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
231
232 } // namespace detail
233 } // namespace asio
234 } // namespace boost
235
236 #include <boost/asio/detail/pop_options.hpp>
237
238 #if defined(BOOST_ASIO_HEADER_ONLY)
239 # include <boost/asio/detail/impl/handler_tracking.ipp>
240 #endif // defined(BOOST_ASIO_HEADER_ONLY)
241
242 #endif // BOOST_ASIO_DETAIL_HANDLER_TRACKING_HPP