Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.3KB

  1. //
  2. // 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. #ifndef ASIO_DEFER_HPP
  11. #define ASIO_DEFER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/async_result.hpp"
  17. #include "asio/detail/type_traits.hpp"
  18. #include "asio/execution_context.hpp"
  19. #include "asio/is_executor.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. /// Submits a completion token or function object for execution.
  23. /**
  24. * This function submits an object for execution using the object's associated
  25. * executor. The function object is queued for execution, and is never called
  26. * from the current thread prior to returning from <tt>defer()</tt>.
  27. *
  28. * The use of @c defer(), rather than @ref post(), indicates the caller's
  29. * preference that the executor defer the queueing of the function object. This
  30. * may allow the executor to optimise queueing for cases when the function
  31. * object represents a continuation of the current call context.
  32. *
  33. * This function has the following effects:
  34. *
  35. * @li Constructs a function object handler of type @c Handler, initialized
  36. * with <tt>handler(forward<CompletionToken>(token))</tt>.
  37. *
  38. * @li Constructs an object @c result of type <tt>async_result<Handler></tt>,
  39. * initializing the object as <tt>result(handler)</tt>.
  40. *
  41. * @li Obtains the handler's associated executor object @c ex by performing
  42. * <tt>get_associated_executor(handler)</tt>.
  43. *
  44. * @li Obtains the handler's associated allocator object @c alloc by performing
  45. * <tt>get_associated_allocator(handler)</tt>.
  46. *
  47. * @li Performs <tt>ex.defer(std::move(handler), alloc)</tt>.
  48. *
  49. * @li Returns <tt>result.get()</tt>.
  50. */
  51. template <typename CompletionToken>
  52. ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer(
  53. ASIO_MOVE_ARG(CompletionToken) token);
  54. /// Submits a completion token or function object for execution.
  55. /**
  56. * This function submits an object for execution using the specified executor.
  57. * The function object is queued for execution, and is never called from the
  58. * current thread prior to returning from <tt>defer()</tt>.
  59. *
  60. * The use of @c defer(), rather than @ref post(), indicates the caller's
  61. * preference that the executor defer the queueing of the function object. This
  62. * may allow the executor to optimise queueing for cases when the function
  63. * object represents a continuation of the current call context.
  64. *
  65. * This function has the following effects:
  66. *
  67. * @li Constructs a function object handler of type @c Handler, initialized
  68. * with <tt>handler(forward<CompletionToken>(token))</tt>.
  69. *
  70. * @li Constructs an object @c result of type <tt>async_result<Handler></tt>,
  71. * initializing the object as <tt>result(handler)</tt>.
  72. *
  73. * @li Obtains the handler's associated executor object @c ex1 by performing
  74. * <tt>get_associated_executor(handler)</tt>.
  75. *
  76. * @li Creates a work object @c w by performing <tt>make_work(ex1)</tt>.
  77. *
  78. * @li Obtains the handler's associated allocator object @c alloc by performing
  79. * <tt>get_associated_allocator(handler)</tt>.
  80. *
  81. * @li Constructs a function object @c f with a function call operator that
  82. * performs <tt>ex1.dispatch(std::move(handler), alloc)</tt> followed by
  83. * <tt>w.reset()</tt>.
  84. *
  85. * @li Performs <tt>Executor(ex).defer(std::move(f), alloc)</tt>.
  86. *
  87. * @li Returns <tt>result.get()</tt>.
  88. */
  89. template <typename Executor, typename CompletionToken>
  90. ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer(
  91. const Executor& ex, ASIO_MOVE_ARG(CompletionToken) token,
  92. typename enable_if<is_executor<Executor>::value>::type* = 0);
  93. /// Submits a completion token or function object for execution.
  94. /**
  95. * @returns <tt>defer(ctx.get_executor(), forward<CompletionToken>(token))</tt>.
  96. */
  97. template <typename ExecutionContext, typename CompletionToken>
  98. ASIO_INITFN_RESULT_TYPE(CompletionToken, void()) defer(
  99. ExecutionContext& ctx, ASIO_MOVE_ARG(CompletionToken) token,
  100. typename enable_if<is_convertible<
  101. ExecutionContext&, execution_context&>::value>::type* = 0);
  102. } // namespace asio
  103. #include "asio/detail/pop_options.hpp"
  104. #include "asio/impl/defer.hpp"
  105. #endif // ASIO_DEFER_HPP