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/platform/windows_runtime.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
64 #if defined(__clang__) && defined(__x86_64__)
65 // clang x64 warns that __stdcall is ignored
66 # define BOOST_SP_STDCALL
68 # define BOOST_SP_STDCALL __stdcall
71 #if defined(__LP64__) // Cygwin 64
72 extern "C" __declspec(dllimport) void BOOST_SP_STDCALL Sleep( unsigned int ms );
74 extern "C" __declspec(dllimport) void BOOST_SP_STDCALL Sleep( unsigned long ms );
77 #undef BOOST_SP_STDCALL
79 #endif // !defined( BOOST_USE_WINDOWS_H ) && !BOOST_PLAT_WINDOWS_RUNTIME
81 inline void yield( unsigned k ) BOOST_NOEXCEPT
86 #if defined( BOOST_SMT_PAUSE )
92 #if !BOOST_PLAT_WINDOWS_RUNTIME
104 // Sleep isn't supported on the Windows Runtime.
105 std::this_thread::yield();
110 } // namespace detail
114 #elif defined( BOOST_HAS_PTHREADS )
119 // AIX's sched.h defines ::var which sometimes conflicts with Lambda's var
120 extern "C" int sched_yield(void);
131 inline void yield( unsigned k )
136 #if defined( BOOST_SMT_PAUSE )
142 else if( k < 32 || k & 1 )
148 // g++ -Wextra warns on {} or {0}
149 struct timespec rqtp = { 0, 0 };
151 // POSIX says that timespec has tv_sec and tv_nsec
152 // But it doesn't guarantee order or placement
157 nanosleep( &rqtp, 0 );
161 } // namespace detail
173 inline void yield( unsigned )
177 } // namespace detail
183 #endif // #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED