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