posix_event.ipp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // detail/impl/posix_event.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2023 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_EVENT_IPP
  11. #define ASIO_DETAIL_IMPL_POSIX_EVENT_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_event.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_event::posix_event()
  24. : state_(0)
  25. {
  26. #if (defined(__MACH__) && defined(__APPLE__)) \
  27. || (defined(__ANDROID__) && (__ANDROID_API__ < 21))
  28. int error = ::pthread_cond_init(&cond_, 0);
  29. #else // (defined(__MACH__) && defined(__APPLE__))
  30. // || (defined(__ANDROID__) && (__ANDROID_API__ < 21))
  31. ::pthread_condattr_t attr;
  32. int error = ::pthread_condattr_init(&attr);
  33. if (error == 0)
  34. {
  35. error = ::pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
  36. if (error == 0)
  37. error = ::pthread_cond_init(&cond_, &attr);
  38. ::pthread_condattr_destroy(&attr);
  39. }
  40. #endif // (defined(__MACH__) && defined(__APPLE__))
  41. // || (defined(__ANDROID__) && (__ANDROID_API__ < 21))
  42. asio::error_code ec(error,
  43. asio::error::get_system_category());
  44. asio::detail::throw_error(ec, "event");
  45. }
  46. } // namespace detail
  47. } // namespace asio
  48. #include "asio/detail/pop_options.hpp"
  49. #endif // defined(ASIO_HAS_PTHREADS)
  50. #endif // ASIO_DETAIL_IMPL_POSIX_EVENT_IPP