system_executor.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // system_executor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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 BOOST_ASIO_SYSTEM_EXECUTOR_HPP
  11. #define BOOST_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 <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/push_options.hpp>
  17. namespace boost {
  18. namespace asio {
  19. class system_context;
  20. /// An executor that uses arbitrary threads.
  21. /**
  22. * The system executor represents an execution context where functions are
  23. * permitted to run on arbitrary threads. The post() and defer() functions
  24. * schedule the function to run on an unspecified system thread pool, and
  25. * dispatch() invokes the function immediately.
  26. */
  27. class system_executor
  28. {
  29. public:
  30. /// Obtain the underlying execution context.
  31. system_context& context() const BOOST_ASIO_NOEXCEPT;
  32. /// Inform the executor that it has some outstanding work to do.
  33. /**
  34. * For the system executor, this is a no-op.
  35. */
  36. void on_work_started() const BOOST_ASIO_NOEXCEPT
  37. {
  38. }
  39. /// Inform the executor that some work is no longer outstanding.
  40. /**
  41. * For the system executor, this is a no-op.
  42. */
  43. void on_work_finished() const BOOST_ASIO_NOEXCEPT
  44. {
  45. }
  46. /// Request the system executor to invoke the given function object.
  47. /**
  48. * This function is used to ask the executor to execute the given function
  49. * object. The function object will always be executed inside this function.
  50. *
  51. * @param f The function object to be called. The executor will make
  52. * a copy of the handler object as required. The function signature of the
  53. * function object must be: @code void function(); @endcode
  54. *
  55. * @param a An allocator that may be used by the executor to allocate the
  56. * internal storage needed for function invocation.
  57. */
  58. template <typename Function, typename Allocator>
  59. void dispatch(BOOST_ASIO_MOVE_ARG(Function) f, const Allocator& a) const;
  60. /// Request the system executor to invoke the given function object.
  61. /**
  62. * This function is used to ask the executor to execute the given function
  63. * object. The function object will never be executed inside this function.
  64. * Instead, it will be scheduled to run on an unspecified system thread pool.
  65. *
  66. * @param f The function object to be called. The executor will make
  67. * a copy of the handler object as required. The function signature of the
  68. * function object must be: @code void function(); @endcode
  69. *
  70. * @param a An allocator that may be used by the executor to allocate the
  71. * internal storage needed for function invocation.
  72. */
  73. template <typename Function, typename Allocator>
  74. void post(BOOST_ASIO_MOVE_ARG(Function) f, const Allocator& a) const;
  75. /// Request the system executor to invoke the given function object.
  76. /**
  77. * This function is used to ask the executor to execute the given function
  78. * object. The function object will never be executed inside this function.
  79. * Instead, it will be scheduled to run on an unspecified system thread pool.
  80. *
  81. * @param f The function object to be called. The executor will make
  82. * a copy of the handler object as required. The function signature of the
  83. * function object must be: @code void function(); @endcode
  84. *
  85. * @param a An allocator that may be used by the executor to allocate the
  86. * internal storage needed for function invocation.
  87. */
  88. template <typename Function, typename Allocator>
  89. void defer(BOOST_ASIO_MOVE_ARG(Function) f, const Allocator& a) const;
  90. /// Compare two executors for equality.
  91. /**
  92. * System executors always compare equal.
  93. */
  94. friend bool operator==(const system_executor&,
  95. const system_executor&) BOOST_ASIO_NOEXCEPT
  96. {
  97. return true;
  98. }
  99. /// Compare two executors for inequality.
  100. /**
  101. * System executors always compare equal.
  102. */
  103. friend bool operator!=(const system_executor&,
  104. const system_executor&) BOOST_ASIO_NOEXCEPT
  105. {
  106. return false;
  107. }
  108. };
  109. } // namespace asio
  110. } // namespace boost
  111. #include <boost/asio/detail/pop_options.hpp>
  112. #include <boost/asio/impl/system_executor.hpp>
  113. #endif // BOOST_ASIO_SYSTEM_EXECUTOR_HPP