11 #ifndef ASIO_EXECUTOR_HPP 12 #define ASIO_EXECUTOR_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) 23 #include "asio/detail/cstddef.hpp" 24 #include "asio/detail/executor_function.hpp" 25 #include "asio/detail/memory.hpp" 26 #include "asio/detail/throw_exception.hpp" 27 #include "asio/execution_context.hpp" 29 #include "asio/detail/push_options.hpp" 35 :
public std::exception
42 ASIO_DECL
virtual const char*
what()
const 43 ASIO_NOEXCEPT_OR_NOTHROW;
64 : impl_(other.clone())
68 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 75 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 78 template <
typename Executor>
83 template <
typename Executor,
typename Allocator>
96 impl_ = other.clone();
100 #if defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 109 #endif // defined(ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION) 121 template <
typename Executor>
124 executor tmp(ASIO_MOVE_CAST(Executor)(e));
134 return get_impl()->context();
140 get_impl()->on_work_started();
146 get_impl()->on_work_finished();
162 template <
typename Function,
typename Allocator>
163 void dispatch(ASIO_MOVE_ARG(Function) f,
const Allocator& a)
const;
178 template <
typename Function,
typename Allocator>
179 void post(ASIO_MOVE_ARG(Function) f,
const Allocator& a)
const;
194 template <
typename Function,
typename Allocator>
195 void defer(ASIO_MOVE_ARG(Function) f,
const Allocator& a)
const;
202 operator unspecified_bool_type() const ASIO_NOEXCEPT
204 return impl_ ? &executor::unspecified_bool_true : 0;
212 #if !defined(ASIO_NO_TYPEID) || defined(GENERATING_DOCUMENTATION) 215 return impl_ ? impl_->target_type() :
typeid(void);
217 #else // !defined(ASIO_NO_TYPEID) || defined(GENERATING_DOCUMENTATION) 218 const void* target_type()
const ASIO_NOEXCEPT
220 return impl_ ? impl_->target_type() : 0;
222 #endif // !defined(ASIO_NO_TYPEID) || defined(GENERATING_DOCUMENTATION) 229 template <
typename Executor>
230 Executor* target() ASIO_NOEXCEPT;
237 template <
typename Executor>
238 const Executor* target()
const ASIO_NOEXCEPT;
244 if (a.impl_ == b.impl_)
246 if (!a.impl_ || !b.impl_)
248 return a.impl_->equals(b.impl_);
259 #if !defined(GENERATING_DOCUMENTATION) 261 template <
typename,
typename>
class impl;
263 #if !defined(ASIO_NO_TYPEID) 264 typedef const std::type_info& type_id_result_type;
265 #else // !defined(ASIO_NO_TYPEID) 266 typedef const void* type_id_result_type;
267 #endif // !defined(ASIO_NO_TYPEID) 269 template <
typename T>
270 static type_id_result_type type_id()
272 #if !defined(ASIO_NO_TYPEID) 274 #else // !defined(ASIO_NO_TYPEID) 275 static int unique_id;
277 #endif // !defined(ASIO_NO_TYPEID) 284 virtual impl_base* clone()
const ASIO_NOEXCEPT = 0;
285 virtual void destroy() ASIO_NOEXCEPT = 0;
287 virtual void on_work_started() ASIO_NOEXCEPT = 0;
288 virtual void on_work_finished() ASIO_NOEXCEPT = 0;
289 virtual void dispatch(ASIO_MOVE_ARG(
function)) = 0;
290 virtual void post(ASIO_MOVE_ARG(
function)) = 0;
291 virtual void defer(ASIO_MOVE_ARG(
function)) = 0;
292 virtual type_id_result_type target_type()
const ASIO_NOEXCEPT = 0;
293 virtual void* target() ASIO_NOEXCEPT = 0;
294 virtual const void* target()
const ASIO_NOEXCEPT = 0;
295 virtual bool equals(
const impl_base* e)
const ASIO_NOEXCEPT = 0;
298 impl_base(
bool fast_dispatch) : fast_dispatch_(fast_dispatch) {}
299 virtual ~impl_base() {}
303 const bool fast_dispatch_;
307 impl_base* get_impl()
const 312 asio::detail::throw_exception(ex);
318 impl_base* clone()
const ASIO_NOEXCEPT
320 return impl_ ? impl_->clone() : 0;
324 void destroy() ASIO_NOEXCEPT
331 #endif // !defined(GENERATING_DOCUMENTATION) 338 #include "asio/detail/pop_options.hpp" 340 #include "asio/impl/executor.hpp" 341 #if defined(ASIO_HEADER_ONLY) 342 # include "asio/impl/executor.ipp" 343 #endif // defined(ASIO_HEADER_ONLY) 345 #endif // !defined(ASIO_NO_TS_EXECUTORS) 347 #endif // ASIO_EXECUTOR_HPP executor & operator=(const executor &other) ASIO_NOEXCEPT
Assignment operator.
Definition: executor.hpp:93
virtual ASIO_DECL const char * what() const ASIO_NOEXCEPT_OR_NOTHROW
Obtain message associated with exception.
Definition: executor.ipp:32
void on_work_finished() const ASIO_NOEXCEPT
Inform the executor that some work is no longer outstanding.
Definition: executor.hpp:144
Exception thrown when trying to access an empty polymorphic executor.
Definition: executor.hpp:34
executor & operator=(nullptr_t) ASIO_NOEXCEPT
Assignment operator for nullptr_t.
Definition: executor.hpp:112
ASIO_DECL bad_executor() ASIO_NOEXCEPT
Constructor.
Definition: executor.ipp:28
friend bool operator!=(const executor &a, const executor &b) ASIO_NOEXCEPT
Compare two executors for inequality.
Definition: executor.hpp:252
Definition: executor.hpp:197
Polymorphic wrapper for executors.
Definition: executor.hpp:47
A context for function object execution.
Definition: execution_context.hpp:105
void on_work_started() const ASIO_NOEXCEPT
Inform the executor that it has some outstanding work to do.
Definition: executor.hpp:138
const std::type_info & target_type() const ASIO_NOEXCEPT
Obtain type information for the target executor object.
Definition: executor.hpp:213
Definition: cstddef.hpp:26
~executor()
Destructor.
Definition: executor.hpp:87
Definition: executor_function.hpp:125
Definition: memory.hpp:64
friend bool operator==(const executor &a, const executor &b) ASIO_NOEXCEPT
Compare two executors for equality.
Definition: executor.hpp:241
executor(const executor &other) ASIO_NOEXCEPT
Copy constructor.
Definition: executor.hpp:63
executor() ASIO_NOEXCEPT
Default constructor.
Definition: executor.hpp:51
execution_context & context() const ASIO_NOEXCEPT
Obtain the underlying execution context.
Definition: executor.hpp:132
executor & operator=(ASIO_MOVE_ARG(Executor) e) ASIO_NOEXCEPT
Assignment operator to create a polymorphic wrapper for the specified executor.
Definition: executor.hpp:122
Definition: any_io_executor.hpp:28
executor(nullptr_t) ASIO_NOEXCEPT
Construct from nullptr.
Definition: executor.hpp:57