pthread_helpers.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef BOOST_THREAD_PTHREAD_PTHREAD_HELPERS_HPP
  2. #define BOOST_THREAD_PTHREAD_PTHREAD_HELPERS_HPP
  3. // Copyright (C) 2017
  4. // Vicente J. Botet Escriba
  5. //
  6. // Distributed under the Boost Software License, Version 1.0. (See
  7. // accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #include <boost/thread/detail/config.hpp>
  10. #include <pthread.h>
  11. #include <boost/config/abi_prefix.hpp>
  12. namespace boost
  13. {
  14. namespace pthread
  15. {
  16. inline int cond_init(pthread_cond_t& cond) {
  17. #ifdef BOOST_THREAD_INTERNAL_CLOCK_IS_MONO
  18. pthread_condattr_t attr;
  19. int res = pthread_condattr_init(&attr);
  20. if (res)
  21. {
  22. return res;
  23. }
  24. pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
  25. res=pthread_cond_init(&cond,&attr);
  26. pthread_condattr_destroy(&attr);
  27. return res;
  28. #else
  29. return pthread_cond_init(&cond,NULL);
  30. #endif
  31. }
  32. }
  33. }
  34. #include <boost/config/abi_suffix.hpp>
  35. #endif