11 #ifndef ASIO_EXECUTOR_WORK_GUARD_HPP 12 #define ASIO_EXECUTOR_WORK_GUARD_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 20 #if !defined(ASIO_NO_TS_EXECUTORS) 22 #include "asio/associated_executor.hpp" 23 #include "asio/detail/type_traits.hpp" 24 #include "asio/execution.hpp" 25 #include "asio/is_executor.hpp" 27 #include "asio/detail/push_options.hpp" 31 #if !defined(ASIO_EXECUTOR_WORK_GUARD_DECL) 32 #define ASIO_EXECUTOR_WORK_GUARD_DECL 34 template <
typename Executor,
typename =
void>
37 #endif // !defined(ASIO_EXECUTOR_WORK_GUARD_DECL) 41 #if defined(GENERATING_DOCUMENTATION) 42 template <
typename Executor>
43 #else // defined(GENERATING_DOCUMENTATION) 44 template <
typename Executor,
typename>
45 #endif // defined(GENERATING_DOCUMENTATION) 60 executor_.on_work_started();
65 : executor_(other.executor_),
69 executor_.on_work_started();
72 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 75 : executor_(ASIO_MOVE_CAST(Executor)(other.executor_)),
80 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 90 executor_.on_work_finished();
114 executor_.on_work_finished();
123 executor_type executor_;
127 #if !defined(GENERATING_DOCUMENTATION) 129 template <
typename Executor>
142 new (&work_) work_type(asio::prefer(executor_,
143 execution::outstanding_work.tracked));
147 : executor_(other.executor_),
152 new (&work_) work_type(asio::prefer(executor_,
153 execution::outstanding_work.tracked));
157 #if defined(ASIO_HAS_MOVE) 159 : executor_(ASIO_MOVE_CAST(Executor)(other.executor_)),
164 new (&work_) work_type(
165 ASIO_MOVE_CAST(work_type)(
166 *
static_cast<work_type*
>(
167 static_cast<void*
>(&other.work_))));
171 #endif // defined(ASIO_HAS_MOVE) 176 static_cast<work_type*
>(
static_cast<void*
>(&work_))->~work_type();
189 void reset() ASIO_NOEXCEPT
193 static_cast<work_type*
>(
static_cast<void*
>(&work_))->~work_type();
202 typedef typename decay<
204 const executor_type&,
209 executor_type executor_;
210 typename aligned_storage<
sizeof(work_type),
211 alignment_of<work_type>::value>::type work_;
215 #endif // !defined(GENERATING_DOCUMENTATION) 218 template <
typename Executor>
228 template <
typename ExecutionContext>
230 make_work_guard(ExecutionContext& ctx,
232 is_convertible<ExecutionContext&, execution_context&>::value
240 template <
typename T>
242 make_work_guard(
const T& t,
246 >::value>::type* = 0)
253 template <
typename T,
typename Executor>
255 make_work_guard(
const T& t,
const Executor& ex,
265 template <
typename T,
typename ExecutionContext>
267 typename ExecutionContext::executor_type>::type>
268 make_work_guard(
const T& t, ExecutionContext& ctx,
271 && !is_convertible<T&, execution_context&>::value
272 && is_convertible<ExecutionContext&, execution_context&>::value
276 typename ExecutionContext::executor_type>::type>(
278 t, ctx.get_executor()));
283 #include "asio/detail/pop_options.hpp" 285 #endif // !defined(ASIO_NO_TS_EXECUTORS) 287 #endif // ASIO_EXECUTOR_WORK_GUARD_HPP executor_type get_executor() const ASIO_NOEXCEPT
Obtain the associated executor.
Definition: executor_work_guard.hpp:94
bool owns_work() const ASIO_NOEXCEPT
Whether the executor_work_guard object owns some outstanding work.
Definition: executor_work_guard.hpp:100
executor_work_guard(const executor_type &e) ASIO_NOEXCEPT
Constructs a executor_work_guard object for the specified executor.
Definition: executor_work_guard.hpp:56
A context for function object execution.
Definition: execution_context.hpp:105
Definition: type_traits.hpp:97
The is_executor trait detects whether a type T meets the Executor type requirements.
Definition: is_executor.hpp:33
Definition: outstanding_work.hpp:153
Executor executor_type
The underlying executor type.
Definition: executor_work_guard.hpp:50
An object of type executor_work_guard controls ownership of executor work within a scope...
Definition: executor_work_guard.hpp:35
Traits type used to obtain the executor associated with an object.
Definition: associated_executor.hpp:76
Definition: prefer.hpp:623
void reset() ASIO_NOEXCEPT
Indicate that the work is no longer outstanding.
Definition: executor_work_guard.hpp:110
~executor_work_guard()
Destructor.
Definition: executor_work_guard.hpp:87
Definition: any_io_executor.hpp:28
executor_work_guard(const executor_work_guard &other) ASIO_NOEXCEPT
Copy constructor.
Definition: executor_work_guard.hpp:64
The is_executor trait detects whether a type T satisfies the execution::executor concept.
Definition: executor.hpp:109