1 #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
4 // MS compatible compilers support #pragma once
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
13 // Copyright (c) 2008 Peter Dimov
14 // Copyright (c) Microsoft Corporation 2014
16 // void yield( unsigned k );
20 // for( unsigned k = 0; !try_lock(); ++k ) yield( k );
22 // Distributed under the Boost Software License, Version 1.0.
23 // See accompanying file LICENSE_1_0.txt or copy at
24 // http://www.boost.org/LICENSE_1_0.txt
27 #include <boost/config.hpp>
28 #include <boost/predef.h>
30 #if BOOST_PLAT_WINDOWS_RUNTIME
36 #if defined(_MSC_VER) && _MSC_VER >= 1310 && ( defined(_M_IX86) || defined(_M_X64) ) && !defined(__c2__)
38 extern "C" void _mm_pause();
40 #define BOOST_SMT_PAUSE _mm_pause();
42 #elif defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
44 #define BOOST_SMT_PAUSE __asm__ __volatile__( "rep; nop" : : : "memory" );
50 #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
52 #if defined( BOOST_USE_WINDOWS_H )
62 #if !defined( BOOST_USE_WINDOWS_H ) && !BOOST_PLAT_WINDOWS_RUNTIME
63 #if !BOOST_COMP_CLANG || !defined __MINGW32__
64 extern "C" void __stdcall Sleep( unsigned long ms );
67 #if !defined __MINGW64_VERSION_MAJOR
68 extern "C" void __stdcall Sleep( unsigned long ms );
70 extern "C" __declspec(dllimport) void __stdcall Sleep( unsigned long ms );
75 inline void yield( unsigned k )
80 #if defined( BOOST_SMT_PAUSE )
86 #if !BOOST_PLAT_WINDOWS_RUNTIME
98 // Sleep isn't supported on the Windows Runtime.
99 std::this_thread::yield();
104 } // namespace detail
108 #elif defined( BOOST_HAS_PTHREADS )
113 // AIX's sched.h defines ::var which sometimes conflicts with Lambda's var
114 extern "C" int sched_yield(void);
125 inline void yield( unsigned k )
130 #if defined( BOOST_SMT_PAUSE )
136 else if( k < 32 || k & 1 )
142 // g++ -Wextra warns on {} or {0}
143 struct timespec rqtp = { 0, 0 };
145 // POSIX says that timespec has tv_sec and tv_nsec
146 // But it doesn't guarantee order or placement
151 nanosleep( &rqtp, 0 );
155 } // namespace detail
167 inline void yield( unsigned )
171 } // namespace detail
177 #endif // #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED