1 #ifndef BOOST_SMART_PTR_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED
2 #define BOOST_SMART_PTR_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/smart_ptr/detail/sp_thread_yield.hpp
11 //
12 // inline void bost::detail::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( __WIN32__ ) || defined( __CYGWIN__ )
25 
26 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
27   BOOST_PRAGMA_MESSAGE("Using Sleep(0) in sp_thread_yield")
28 #endif
29 
30 #include <boost/smart_ptr/detail/sp_win32_sleep.hpp>
31 
32 namespace boost
33 {
34 
35 namespace detail
36 {
37 
sp_thread_yield()38 inline void sp_thread_yield()
39 {
40     Sleep( 0 );
41 }
42 
43 } // namespace detail
44 
45 } // namespace boost
46 
47 #elif defined(BOOST_HAS_SCHED_YIELD)
48 
49 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
50   BOOST_PRAGMA_MESSAGE("Using sched_yield() in sp_thread_yield")
51 #endif
52 
53 #ifndef _AIX
54 # include <sched.h>
55 #else
56   // AIX's sched.h defines ::var which sometimes conflicts with Lambda's var
57   extern "C" int sched_yield(void);
58 #endif
59 
60 namespace boost
61 {
62 
63 namespace detail
64 {
65 
sp_thread_yield()66 inline void sp_thread_yield()
67 {
68     sched_yield();
69 }
70 
71 } // namespace detail
72 
73 } // namespace boost
74 
75 #else
76 
77 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
78   BOOST_PRAGMA_MESSAGE("Using sp_thread_pause() in sp_thread_yield")
79 #endif
80 
81 #include <boost/smart_ptr/detail/sp_thread_pause.hpp>
82 
83 namespace boost
84 {
85 
86 namespace detail
87 {
88 
sp_thread_yield()89 inline void sp_thread_yield()
90 {
91     sp_thread_pause();
92 }
93 
94 } // namespace detail
95 
96 } // namespace boost
97 
98 #endif
99 
100 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_THREAD_YIELD_HPP_INCLUDED
101