system_context.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // system_context.hpp
  3. // ~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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_CONTEXT_HPP
  11. #define BOOST_ASIO_SYSTEM_CONTEXT_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/scheduler.hpp>
  17. #include <boost/asio/detail/thread_group.hpp>
  18. #include <boost/asio/execution.hpp>
  19. #include <boost/asio/execution_context.hpp>
  20. #include <boost/asio/detail/push_options.hpp>
  21. namespace boost {
  22. namespace asio {
  23. template <typename Blocking, typename Relationship, typename Allocator>
  24. class basic_system_executor;
  25. /// The executor context for the system executor.
  26. class system_context : public execution_context
  27. {
  28. public:
  29. /// The executor type associated with the context.
  30. typedef basic_system_executor<
  31. execution::blocking_t::possibly_t,
  32. execution::relationship_t::fork_t,
  33. std::allocator<void>
  34. > executor_type;
  35. /// Destructor shuts down all threads in the system thread pool.
  36. BOOST_ASIO_DECL ~system_context();
  37. /// Obtain an executor for the context.
  38. executor_type get_executor() noexcept;
  39. /// Signal all threads in the system thread pool to stop.
  40. BOOST_ASIO_DECL void stop();
  41. /// Determine whether the system thread pool has been stopped.
  42. BOOST_ASIO_DECL bool stopped() const noexcept;
  43. /// Join all threads in the system thread pool.
  44. BOOST_ASIO_DECL void join();
  45. #if defined(GENERATING_DOCUMENTATION)
  46. private:
  47. #endif // defined(GENERATING_DOCUMENTATION)
  48. // Constructor creates all threads in the system thread pool.
  49. BOOST_ASIO_DECL system_context();
  50. private:
  51. template <typename, typename, typename> friend class basic_system_executor;
  52. struct thread_function;
  53. // Helper function to create the underlying scheduler.
  54. BOOST_ASIO_DECL detail::scheduler& add_scheduler(detail::scheduler* s);
  55. // The underlying scheduler.
  56. detail::scheduler& scheduler_;
  57. // The threads in the system thread pool.
  58. detail::thread_group threads_;
  59. // The number of threads in the pool.
  60. std::size_t num_threads_;
  61. };
  62. } // namespace asio
  63. } // namespace boost
  64. #include <boost/asio/detail/pop_options.hpp>
  65. #include <boost/asio/impl/system_context.hpp>
  66. #if defined(BOOST_ASIO_HEADER_ONLY)
  67. # include <boost/asio/impl/system_context.ipp>
  68. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  69. #endif // BOOST_ASIO_SYSTEM_CONTEXT_HPP