• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
2 #define BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
3 
4 // MS compatible compilers support #pragma once
5 
6 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
7 # pragma once
8 #endif
9 
10 // boost/smart_ptr/detail/yield_k.hpp
11 //
12 // Copyright 2008, 2020 Peter Dimov
13 //
14 // inline void boost::detail::yield( unsigned k );
15 //
16 //   Typical use:
17 //   for( unsigned k = 0; !try_lock(); ++k ) yield( k );
18 //
19 // Distributed under the Boost Software License, Version 1.0.
20 // https://www.boost.org/LICENSE_1_0.txt
21 
22 #include <boost/smart_ptr/detail/sp_thread_pause.hpp>
23 #include <boost/smart_ptr/detail/sp_thread_sleep.hpp>
24 #include <boost/config.hpp>
25 
26 namespace boost
27 {
28 
29 namespace detail
30 {
31 
yield(unsigned k)32 inline void yield( unsigned k )
33 {
34     // Experiments on Windows and Fedora 32 show that a single pause,
35     // followed by an immediate sp_thread_sleep(), is best.
36 
37     if( k == 0 )
38     {
39         sp_thread_pause();
40     }
41     else
42     {
43         sp_thread_sleep();
44     }
45 }
46 
47 } // namespace detail
48 
49 } // namespace boost
50 
51 #endif // #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
52