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();
34 #define BOOST_SMT_PAUSE _mm_pause();
36 #elif defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
38 #define BOOST_SMT_PAUSE __asm__ __volatile__( "rep; nop" : : : "memory" );
44 #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
46 #if defined( BOOST_USE_WINDOWS_H )
56 #if !defined( BOOST_USE_WINDOWS_H )
57 extern "C" void __stdcall Sleep( unsigned long ms );
60 inline void yield( unsigned k )
65 #if defined( BOOST_SMT_PAUSE )
85 #elif defined( BOOST_HAS_PTHREADS )
96 inline void yield( unsigned k )
101 #if defined( BOOST_SMT_PAUSE )
107 else if( k < 32 || k & 1 )
113 // g++ -Wextra warns on {} or {0}
114 struct timespec rqtp = { 0, 0 };
116 // POSIX says that timespec has tv_sec and tv_nsec
117 // But it doesn't guarantee order or placement
122 nanosleep( &rqtp, 0 );
126 } // namespace detail
138 inline void yield( unsigned )
142 } // namespace detail
148 #endif // #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED