execution_context.ipp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // impl/execution_context.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2025 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_IMPL_EXECUTION_CONTEXT_IPP
  11. #define BOOST_ASIO_IMPL_EXECUTION_CONTEXT_IPP
  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/execution_context.hpp>
  17. #include <boost/asio/detail/service_registry.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. execution_context::execution_context()
  22. : execution_context(
  23. detail::allocate_object<allocator_impl<std::allocator<void>>>(
  24. std::allocator<void>(), std::allocator<void>()))
  25. {
  26. }
  27. execution_context::execution_context(allocator_impl_base* alloc)
  28. : allocator_{alloc},
  29. service_registry_(
  30. detail::allocate_object<detail::service_registry>(
  31. allocator<void>(*this), *this))
  32. {
  33. }
  34. execution_context::execution_context(
  35. const execution_context::service_maker& initial_services)
  36. : execution_context(
  37. detail::allocate_object<allocator_impl<std::allocator<void>>>(
  38. std::allocator<void>(), std::allocator<void>()),
  39. initial_services)
  40. {
  41. }
  42. execution_context::execution_context(allocator_impl_base* alloc,
  43. const execution_context::service_maker& initial_services)
  44. : allocator_{alloc},
  45. service_registry_(
  46. detail::allocate_object<detail::service_registry>(
  47. allocator<void>(*this), *this))
  48. {
  49. initial_services.make(*this);
  50. }
  51. execution_context::~execution_context()
  52. {
  53. shutdown();
  54. destroy();
  55. detail::deallocate_object(allocator<void>(*this), service_registry_);
  56. }
  57. void execution_context::shutdown()
  58. {
  59. service_registry_->shutdown_services();
  60. }
  61. void execution_context::destroy()
  62. {
  63. service_registry_->destroy_services();
  64. }
  65. void execution_context::notify_fork(
  66. boost::asio::execution_context::fork_event event)
  67. {
  68. service_registry_->notify_fork(event);
  69. }
  70. execution_context::allocator_impl_base::~allocator_impl_base()
  71. {
  72. }
  73. execution_context::service::service(execution_context& owner)
  74. : owner_(owner),
  75. next_(0),
  76. destroy_(0)
  77. {
  78. }
  79. execution_context::service::~service()
  80. {
  81. }
  82. void execution_context::service::notify_fork(execution_context::fork_event)
  83. {
  84. }
  85. execution_context::service_maker::~service_maker()
  86. {
  87. }
  88. service_already_exists::service_already_exists()
  89. : std::logic_error("Service already exists.")
  90. {
  91. }
  92. invalid_service_owner::invalid_service_owner()
  93. : std::logic_error("Invalid service owner.")
  94. {
  95. }
  96. } // namespace asio
  97. } // namespace boost
  98. #include <boost/asio/detail/pop_options.hpp>
  99. #endif // BOOST_ASIO_IMPL_EXECUTION_CONTEXT_IPP