Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:59:51

0001 #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
0002 #define BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
0003 
0004 // MS compatible compilers support #pragma once
0005 
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009 
0010 // boost/smart_ptr/detail/yield_k.hpp
0011 //
0012 // Copyright 2008, 2020 Peter Dimov
0013 //
0014 // inline void boost::detail::yield( unsigned k );
0015 //
0016 //   Typical use:
0017 //   for( unsigned k = 0; !try_lock(); ++k ) yield( k );
0018 //
0019 // Distributed under the Boost Software License, Version 1.0.
0020 // https://www.boost.org/LICENSE_1_0.txt
0021 
0022 #include <boost/core/yield_primitives.hpp>
0023 
0024 namespace boost
0025 {
0026 
0027 namespace detail
0028 {
0029 
0030 inline void yield( unsigned k )
0031 {
0032     // Experiments on Windows and Fedora 32 show that a single pause,
0033     // followed by an immediate sp_thread_sleep(), is best.
0034 
0035     if( k & 1 )
0036     {
0037         boost::core::sp_thread_sleep();
0038     }
0039     else
0040     {
0041         boost::core::sp_thread_pause();
0042     }
0043 }
0044 
0045 } // namespace detail
0046 
0047 } // namespace boost
0048 
0049 #endif // #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED