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.

77 lines
1.5KB

  1. //
  2. // impl/thread_pool.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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_THREAD_POOL_IPP
  11. #define ASIO_IMPL_THREAD_POOL_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/thread_pool.hpp"
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. struct thread_pool::thread_function
  20. {
  21. detail::scheduler* scheduler_;
  22. void operator()()
  23. {
  24. asio::error_code ec;
  25. scheduler_->run(ec);
  26. }
  27. };
  28. thread_pool::thread_pool()
  29. : scheduler_(use_service<detail::scheduler>(*this))
  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. thread_pool::thread_pool(std::size_t num_threads)
  37. : scheduler_(use_service<detail::scheduler>(*this))
  38. {
  39. scheduler_.work_started();
  40. thread_function f = { &scheduler_ };
  41. threads_.create_threads(f, num_threads);
  42. }
  43. thread_pool::~thread_pool()
  44. {
  45. stop();
  46. join();
  47. }
  48. void thread_pool::stop()
  49. {
  50. scheduler_.stop();
  51. }
  52. void thread_pool::join()
  53. {
  54. scheduler_.work_finished();
  55. threads_.join();
  56. }
  57. } // namespace asio
  58. #include "asio/detail/pop_options.hpp"
  59. #endif // ASIO_IMPL_THREAD_POOL_IPP