system_context.hpp 2.0 KB

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