sp_thread_yield.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED
  2. #define BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  5. # pragma once
  6. #endif
  7. // boost/core/detail/sp_thread_yield.hpp
  8. //
  9. // inline void bost::core::sp_thread_yield();
  10. //
  11. // Gives up the remainder of the time slice,
  12. // as if by calling sched_yield().
  13. //
  14. // Copyright 2008, 2020 Peter Dimov
  15. // Distributed under the Boost Software License, Version 1.0
  16. // https://www.boost.org/LICENSE_1_0.txt
  17. #include <boost/config.hpp>
  18. #include <boost/config/pragma_message.hpp>
  19. #if defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
  20. #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
  21. BOOST_PRAGMA_MESSAGE("Using SwitchToThread() in sp_thread_yield")
  22. #endif
  23. #include <boost/core/detail/sp_win32_sleep.hpp>
  24. namespace boost
  25. {
  26. namespace core
  27. {
  28. namespace detail
  29. {
  30. inline void sp_thread_yield() BOOST_NOEXCEPT
  31. {
  32. SwitchToThread();
  33. }
  34. } // namespace detail
  35. using boost::core::detail::sp_thread_yield;
  36. } // namespace core
  37. } // namespace boost
  38. #elif defined(BOOST_HAS_SCHED_YIELD)
  39. #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
  40. BOOST_PRAGMA_MESSAGE("Using sched_yield() in sp_thread_yield")
  41. #endif
  42. #ifndef _AIX
  43. # include <sched.h>
  44. #else
  45. // AIX's sched.h defines ::var which sometimes conflicts with Lambda's var
  46. extern "C" int sched_yield(void);
  47. #endif
  48. namespace boost
  49. {
  50. namespace core
  51. {
  52. inline void sp_thread_yield() BOOST_NOEXCEPT
  53. {
  54. sched_yield();
  55. }
  56. } // namespace core
  57. } // namespace boost
  58. #else
  59. #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
  60. BOOST_PRAGMA_MESSAGE("Using sp_thread_pause() in sp_thread_yield")
  61. #endif
  62. #include <boost/core/detail/sp_thread_pause.hpp>
  63. namespace boost
  64. {
  65. namespace core
  66. {
  67. inline void sp_thread_yield() BOOST_NOEXCEPT
  68. {
  69. sp_thread_pause();
  70. }
  71. } // namespace core
  72. } // namespace boost
  73. #endif
  74. #endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED