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.

85 lines
1.8KB

  1. //
  2. // detail/impl/posix_thread.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_DETAIL_IMPL_POSIX_THREAD_IPP
  11. #define ASIO_DETAIL_IMPL_POSIX_THREAD_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. #if defined(ASIO_HAS_PTHREADS)
  17. #include "asio/detail/posix_thread.hpp"
  18. #include "asio/detail/throw_error.hpp"
  19. #include "asio/error.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace detail {
  23. posix_thread::~posix_thread()
  24. {
  25. if (!joined_)
  26. ::pthread_detach(thread_);
  27. }
  28. void posix_thread::join()
  29. {
  30. if (!joined_)
  31. {
  32. ::pthread_join(thread_, 0);
  33. joined_ = true;
  34. }
  35. }
  36. std::size_t posix_thread::hardware_concurrency()
  37. {
  38. #if defined(_SC_NPROCESSORS_ONLN)
  39. long result = sysconf(_SC_NPROCESSORS_ONLN);
  40. if (result > 0)
  41. return result;
  42. #endif // defined(_SC_NPROCESSORS_ONLN)
  43. return 0;
  44. }
  45. void posix_thread::start_thread(func_base* arg)
  46. {
  47. int error = ::pthread_create(&thread_, 0,
  48. asio_detail_posix_thread_function, arg);
  49. if (error != 0)
  50. {
  51. delete arg;
  52. asio::error_code ec(error,
  53. asio::error::get_system_category());
  54. asio::detail::throw_error(ec, "thread");
  55. }
  56. }
  57. void* asio_detail_posix_thread_function(void* arg)
  58. {
  59. posix_thread::auto_func_base_ptr func = {
  60. static_cast<posix_thread::func_base*>(arg) };
  61. func.ptr->run();
  62. return 0;
  63. }
  64. } // namespace detail
  65. } // namespace asio
  66. #include "asio/detail/pop_options.hpp"
  67. #endif // defined(ASIO_HAS_PTHREADS)
  68. #endif // ASIO_DETAIL_IMPL_POSIX_THREAD_IPP