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
15 // void yield( unsigned k );
19 // for( unsigned k = 0; !try_lock(); ++k ) yield( k );
21 // Distributed under the Boost Software License, Version 1.0.
22 // See accompanying file LICENSE_1_0.txt or copy at
23 // http://www.boost.org/LICENSE_1_0.txt
26 #include <boost/config.hpp>
30 #if defined(_MSC_VER) && _MSC_VER >= 1310 && ( defined(_M_IX86) || defined(_M_X64) )
32 extern "C" void _mm_pause();
33 #pragma intrinsic( _mm_pause )
35 #define BOOST_SMT_PAUSE _mm_pause();
37 #elif defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
39 #define BOOST_SMT_PAUSE __asm__ __volatile__( "rep; nop" : : : "memory" );
45 #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
47 #if defined( BOOST_USE_WINDOWS_H )
57 #if !defined( BOOST_USE_WINDOWS_H )
58 extern "C" void __stdcall Sleep( unsigned long ms );
61 inline void yield( unsigned k )
66 #if defined( BOOST_SMT_PAUSE )
86 #elif defined( BOOST_HAS_PTHREADS )
97 inline void yield( unsigned k )
102 #if defined( BOOST_SMT_PAUSE )
108 else if( k < 32 || k & 1 )
114 // g++ -Wextra warns on {} or {0}
115 struct timespec rqtp = { 0, 0 };
117 // POSIX says that timespec has tv_sec and tv_nsec
118 // But it doesn't guarantee order or placement
123 nanosleep( &rqtp, 0 );
127 } // namespace detail
139 inline void yield( unsigned )
143 } // namespace detail
149 #endif // #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED