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.

system_executor.hpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // system_executor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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_SYSTEM_EXECUTOR_HPP
  11. #define ASIO_SYSTEM_EXECUTOR_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/detail/scheduler.hpp"
  17. #include "asio/detail/thread_group.hpp"
  18. #include "asio/execution_context.hpp"
  19. #include "asio/is_executor.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. /// An executor that uses arbitrary threads.
  23. /**
  24. * The system executor represents an execution context where functions are
  25. * permitted to run on arbitrary threads. The post() and defer() functions
  26. * schedule the function to run on an unspecified system thread pool, and
  27. * dispatch() invokes the function immediately.
  28. */
  29. class system_executor
  30. {
  31. public:
  32. /// Obtain the underlying execution context.
  33. execution_context& context() const ASIO_NOEXCEPT;
  34. /// Inform the executor that it has some outstanding work to do.
  35. /**
  36. * For the system executor, this is a no-op.
  37. */
  38. void on_work_started() const ASIO_NOEXCEPT
  39. {
  40. }
  41. /// Inform the executor that some work is no longer outstanding.
  42. /**
  43. * For the system executor, this is a no-op.
  44. */
  45. void on_work_finished() const ASIO_NOEXCEPT
  46. {
  47. }
  48. /// Request the system executor to invoke the given function object.
  49. /**
  50. * This function is used to ask the executor to execute the given function
  51. * object. The function object will always be executed inside this function.
  52. *
  53. * @param f The function object to be called. The executor will make
  54. * a copy of the handler object as required. The function signature of the
  55. * function object must be: @code void function(); @endcode
  56. *
  57. * @param a An allocator that may be used by the executor to allocate the
  58. * internal storage needed for function invocation.
  59. */
  60. template <typename Function, typename Allocator>
  61. void dispatch(ASIO_MOVE_ARG(Function) f, const Allocator& a) const;
  62. /// Request the system executor to invoke the given function object.
  63. /**
  64. * This function is used to ask the executor to execute the given function
  65. * object. The function object will never be executed inside this function.
  66. * Instead, it will be scheduled to run on an unspecified system thread pool.
  67. *
  68. * @param f The function object to be called. The executor will make
  69. * a copy of the handler object as required. The function signature of the
  70. * function object must be: @code void function(); @endcode
  71. *
  72. * @param a An allocator that may be used by the executor to allocate the
  73. * internal storage needed for function invocation.
  74. */
  75. template <typename Function, typename Allocator>
  76. void post(ASIO_MOVE_ARG(Function) f, const Allocator& a) const;
  77. /// Request the system executor to invoke the given function object.
  78. /**
  79. * This function is used to ask the executor to execute the given function
  80. * object. The function object will never be executed inside this function.
  81. * Instead, it will be scheduled to run on an unspecified system thread pool.
  82. *
  83. * @param f The function object to be called. The executor will make
  84. * a copy of the handler object as required. The function signature of the
  85. * function object must be: @code void function(); @endcode
  86. *
  87. * @param a An allocator that may be used by the executor to allocate the
  88. * internal storage needed for function invocation.
  89. */
  90. template <typename Function, typename Allocator>
  91. void defer(ASIO_MOVE_ARG(Function) f, const Allocator& a) const;
  92. /// Compare two executors for equality.
  93. /**
  94. * System executors always compare equal.
  95. */
  96. friend bool operator==(const system_executor&,
  97. const system_executor&) ASIO_NOEXCEPT
  98. {
  99. return true;
  100. }
  101. /// Compare two executors for inequality.
  102. /**
  103. * System executors always compare equal.
  104. */
  105. friend bool operator!=(const system_executor&,
  106. const system_executor&) ASIO_NOEXCEPT
  107. {
  108. return false;
  109. }
  110. private:
  111. struct thread_function;
  112. // Hidden implementation of the system execution context.
  113. struct context_impl
  114. : public execution_context
  115. {
  116. // Constructor creates all threads in the system thread pool.
  117. ASIO_DECL context_impl();
  118. // Destructor shuts down all threads in the system thread pool.
  119. ASIO_DECL ~context_impl();
  120. // The underlying scheduler.
  121. detail::scheduler& scheduler_;
  122. // The threads in the system thread pool.
  123. detail::thread_group threads_;
  124. };
  125. };
  126. #if !defined(GENERATING_DOCUMENTATION)
  127. template <> struct is_executor<system_executor> : true_type {};
  128. #endif // !defined(GENERATING_DOCUMENTATION)
  129. } // namespace asio
  130. #include "asio/detail/pop_options.hpp"
  131. #include "asio/impl/system_executor.hpp"
  132. #if defined(ASIO_HEADER_ONLY)
  133. # include "asio/impl/system_executor.ipp"
  134. #endif // defined(ASIO_HEADER_ONLY)
  135. #endif // ASIO_SYSTEM_EXECUTOR_HPP