system_context.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // system_context.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_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_context.hpp>
  19. #include <boost/asio/detail/push_options.hpp>
  20. namespace boost {
  21. namespace asio {
  22. class system_executor;
  23. /// The executor context for the system executor.
  24. class system_context : public execution_context
  25. {
  26. public:
  27. /// The executor type associated with the context.
  28. typedef system_executor executor_type;
  29. /// Destructor shuts down all threads in the system thread pool.
  30. BOOST_ASIO_DECL ~system_context();
  31. /// Obtain an executor for the context.
  32. executor_type get_executor() BOOST_ASIO_NOEXCEPT;
  33. /// Signal all threads in the system thread pool to stop.
  34. BOOST_ASIO_DECL void stop();
  35. /// Determine whether the system thread pool has been stopped.
  36. BOOST_ASIO_DECL bool stopped() const BOOST_ASIO_NOEXCEPT;
  37. /// Join all threads in the system thread pool.
  38. BOOST_ASIO_DECL void join();
  39. #if defined(GENERATING_DOCUMENTATION)
  40. private:
  41. #endif // defined(GENERATING_DOCUMENTATION)
  42. // Constructor creates all threads in the system thread pool.
  43. BOOST_ASIO_DECL system_context();
  44. private:
  45. friend class system_executor;
  46. struct thread_function;
  47. // The underlying scheduler.
  48. detail::scheduler& scheduler_;
  49. // The threads in the system thread pool.
  50. detail::thread_group threads_;
  51. };
  52. } // namespace asio
  53. } // namespace boost
  54. #include <boost/asio/detail/pop_options.hpp>
  55. #include <boost/asio/impl/system_context.hpp>
  56. #if defined(BOOST_ASIO_HEADER_ONLY)
  57. # include <boost/asio/impl/system_context.ipp>
  58. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  59. #endif // BOOST_ASIO_SYSTEM_CONTEXT_HPP