11 #ifndef ASIO_DETAIL_HANDLER_WORK_HPP 12 #define ASIO_DETAIL_HANDLER_WORK_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 19 #include "asio/associated_executor.hpp" 20 #include "asio/detail/handler_invoke_helpers.hpp" 21 #include "asio/detail/type_traits.hpp" 22 #include "asio/execution/allocator.hpp" 23 #include "asio/execution/blocking.hpp" 24 #include "asio/execution/execute.hpp" 25 #include "asio/execution/executor.hpp" 26 #include "asio/execution/outstanding_work.hpp" 27 #include "asio/executor_work_guard.hpp" 28 #include "asio/prefer.hpp" 30 #include "asio/detail/push_options.hpp" 39 #if defined(ASIO_HAS_VARIADIC_TEMPLATES) 41 template <
typename...>
class any_executor;
43 #else // defined(ASIO_HAS_VARIADIC_TEMPLATES) 45 template <
typename,
typename,
typename,
typename,
typename,
48 #endif // defined(ASIO_HAS_VARIADIC_TEMPLATES) 53 template <
typename Executor,
typename CandidateExecutor = void,
55 typename PolymorphicExecutor =
executor,
typename =
void>
60 : executor_(asio::prefer(ex, execution::outstanding_work.tracked))
64 template <
typename OtherExecutor>
66 const OtherExecutor&) ASIO_NOEXCEPT
67 : executor_(asio::prefer(ex, execution::outstanding_work.tracked))
72 : executor_(other.executor_)
76 #if defined(ASIO_HAS_MOVE) 78 : executor_(ASIO_MOVE_CAST(executor_type)(other.executor_))
81 #endif // defined(ASIO_HAS_MOVE) 83 bool owns_work()
const ASIO_NOEXCEPT
88 template <
typename Function,
typename Handler>
89 void dispatch(Function&
function, Handler& handler)
92 asio::prefer(executor_,
93 execution::blocking.possibly,
94 execution::allocator((get_associated_allocator)(handler))),
95 ASIO_MOVE_CAST(Function)(
function));
99 typedef typename decay<
103 >::type executor_type;
105 executor_type executor_;
108 template <
typename Executor,
typename CandidateExecutor,
109 typename IoContext,
typename PolymorphicExecutor>
111 IoContext, PolymorphicExecutor,
114 && (!is_same<Executor, PolymorphicExecutor>::value
115 || !is_same<CandidateExecutor, void>::value)
123 executor_.on_work_started();
127 const Executor& candidate) ASIO_NOEXCEPT
129 owns_work_(ex != candidate)
132 executor_.on_work_started();
135 template <
typename OtherExecutor>
137 const OtherExecutor&) ASIO_NOEXCEPT
141 executor_.on_work_started();
145 : executor_(other.executor_),
146 owns_work_(other.owns_work_)
149 executor_.on_work_started();
152 #if defined(ASIO_HAS_MOVE) 154 : executor_(ASIO_MOVE_CAST(Executor)(other.executor_)),
155 owns_work_(other.owns_work_)
157 other.owns_work_ =
false;
159 #endif // defined(ASIO_HAS_MOVE) 164 executor_.on_work_finished();
167 bool owns_work()
const ASIO_NOEXCEPT
172 template <
typename Function,
typename Handler>
173 void dispatch(Function&
function, Handler& handler)
175 executor_.dispatch(ASIO_MOVE_CAST(Function)(
function),
176 asio::get_associated_allocator(handler));
184 template <
typename Executor,
typename IoContext,
typename PolymorphicExecutor>
189 typename IoContext::executor_type
198 bool owns_work()
const ASIO_NOEXCEPT
203 template <
typename Function,
typename Handler>
204 void dispatch(Function&
function, Handler& handler)
209 asio_handler_invoke_helpers::invoke(
function, handler);
213 template <
typename Executor,
typename IoContext>
218 #if !defined(ASIO_NO_TYPEID) 220 ex.target_type() ==
typeid(
typename IoContext::executor_type)
224 #endif // !defined(ASIO_NO_TYPEID) 227 executor_.on_work_started();
231 const Executor& candidate) ASIO_NOEXCEPT
232 : executor_(ex != candidate ? ex : Executor())
235 executor_.on_work_started();
238 template <
typename OtherExecutor>
240 const OtherExecutor&) ASIO_NOEXCEPT
243 executor_.on_work_started();
247 : executor_(other.executor_)
250 executor_.on_work_started();
253 #if defined(ASIO_HAS_MOVE) 255 : executor_(ASIO_MOVE_CAST(Executor)(other.executor_))
258 #endif // defined(ASIO_HAS_MOVE) 263 executor_.on_work_finished();
266 bool owns_work()
const ASIO_NOEXCEPT
271 template <
typename Function,
typename Handler>
272 void dispatch(Function&
function, Handler& handler)
274 executor_.dispatch(ASIO_MOVE_CAST(Function)(
function),
275 asio::get_associated_allocator(handler));
283 #if defined(ASIO_HAS_VARIADIC_TEMPLATES) 284 typename... SupportableProperties,
285 #else // defined(ASIO_HAS_VARIADIC_TEMPLATES) 286 typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
287 typename T6,
typename T7,
typename T8,
typename T9,
288 #endif // defined(ASIO_HAS_VARIADIC_TEMPLATES) 289 typename IoContext,
typename PolymorphicExecutor>
291 #if defined(ASIO_HAS_VARIADIC_TEMPLATES)
292 execution::any_executor<SupportableProperties...>,
293 #else // defined(ASIO_HAS_VARIADIC_TEMPLATES) 295 #endif // defined(ASIO_HAS_VARIADIC_TEMPLATES) 296 void, IoContext, PolymorphicExecutor>
300 #if defined(ASIO_HAS_VARIADIC_TEMPLATES) 302 #else // defined(ASIO_HAS_VARIADIC_TEMPLATES) 304 #endif // defined(ASIO_HAS_VARIADIC_TEMPLATES) 308 #if !defined(ASIO_NO_TYPEID) 310 ex.target_type() ==
typeid(
typename IoContext::executor_type)
312 : asio::prefer(ex, execution::outstanding_work.tracked))
314 : executor_(asio::prefer(ex, execution::outstanding_work.tracked))
320 const executor_type& candidate) ASIO_NOEXCEPT
321 : executor_(ex != candidate ? ex : executor_type())
325 template <
typename OtherExecutor>
327 const OtherExecutor&) ASIO_NOEXCEPT
328 : executor_(asio::prefer(ex, execution::outstanding_work.tracked))
333 : executor_(other.executor_)
337 #if defined(ASIO_HAS_MOVE) 339 : executor_(ASIO_MOVE_CAST(executor_type)(other.executor_))
342 #endif // defined(ASIO_HAS_MOVE) 344 bool owns_work()
const ASIO_NOEXCEPT
349 template <
typename Function,
typename Handler>
350 void dispatch(Function&
function, Handler& handler)
353 asio::prefer(executor_,
354 execution::blocking.possibly,
355 execution::allocator((get_associated_allocator)(handler))),
356 ASIO_MOVE_CAST(Function)(
function));
360 executor_type executor_;
363 template <
typename Handler,
typename IoExecutor,
typename =
void>
367 Handler, IoExecutor>::type, IoExecutor>
372 Handler, IoExecutor>::type, IoExecutor>
base2_type;
374 handler_work(Handler& handler,
const IoExecutor& io_ex) ASIO_NOEXCEPT
376 base2_type(asio::get_associated_executor(handler, io_ex), io_ex)
380 template <
typename Function>
381 void complete(Function&
function, Handler& handler)
383 if (!base1_type::owns_work() && !base2_type::owns_work())
388 asio_handler_invoke_helpers::invoke(
function, handler);
392 base2_type::dispatch(
function, handler);
397 template <
typename Handler,
typename IoExecutor>
403 IoExecutor>::asio_associated_executor_is_unspecialised,
411 handler_work(Handler&,
const IoExecutor& io_ex) ASIO_NOEXCEPT
416 template <
typename Function>
417 void complete(Function&
function, Handler& handler)
419 if (!base1_type::owns_work())
424 asio_handler_invoke_helpers::invoke(
function, handler);
428 base1_type::dispatch(
function, handler);
436 #include "asio/detail/pop_options.hpp" 438 #endif // ASIO_DETAIL_HANDLER_WORK_HPP Definition: handler_work.hpp:364
Definition: bulk_execute.cpp:152
Polymorphic wrapper for executors.
Definition: executor.hpp:47
Provides core I/O functionality.
Definition: io_context.hpp:211
Definition: is_executor.hpp:114
Definition: type_traits.hpp:97
Definition: handler_work.hpp:46
Definition: outstanding_work.hpp:153
Traits type used to obtain the executor associated with an object.
Definition: associated_executor.hpp:76
Definition: prefer.hpp:623
Definition: handler_work.hpp:37
Definition: any_io_executor.hpp:28
Definition: handler_work.hpp:56