Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.7KB

  1. //
  2. // impl/system_context.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_IMPL_SYSTEM_CONTEXT_IPP
  11. #define ASIO_IMPL_SYSTEM_CONTEXT_IPP
  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/system_context.hpp"
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. struct system_context::thread_function
  20. {
  21. detail::scheduler* scheduler_;
  22. void operator()()
  23. {
  24. asio::error_code ec;
  25. scheduler_->run(ec);
  26. }
  27. };
  28. system_context::system_context()
  29. : scheduler_(add_scheduler(new detail::scheduler(*this, 0, false)))
  30. {
  31. scheduler_.work_started();
  32. thread_function f = { &scheduler_ };
  33. std::size_t num_threads = detail::thread::hardware_concurrency() * 2;
  34. threads_.create_threads(f, num_threads ? num_threads : 2);
  35. }
  36. system_context::~system_context()
  37. {
  38. scheduler_.work_finished();
  39. scheduler_.stop();
  40. threads_.join();
  41. }
  42. void system_context::stop()
  43. {
  44. scheduler_.stop();
  45. }
  46. bool system_context::stopped() const ASIO_NOEXCEPT
  47. {
  48. return scheduler_.stopped();
  49. }
  50. void system_context::join()
  51. {
  52. scheduler_.work_finished();
  53. threads_.join();
  54. }
  55. detail::scheduler& system_context::add_scheduler(detail::scheduler* s)
  56. {
  57. detail::scoped_ptr<detail::scheduler> scoped_impl(s);
  58. asio::add_service<detail::scheduler>(*this, scoped_impl.get());
  59. return *scoped_impl.release();
  60. }
  61. } // namespace asio
  62. #include "asio/detail/pop_options.hpp"
  63. #endif // ASIO_IMPL_SYSTEM_CONTEXT_IPP