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/core/yield_primitives.hpp>
23
24namespace boost
25{
26
27namespace detail
28{
29
30inline void yield( unsigned k )
31{
32 // Experiments on Windows and Fedora 32 show that a single pause,
33 // followed by an immediate sp_thread_sleep(), is best.
34
35 if( k & 1 )
36 {
37 boost::core::sp_thread_sleep();
38 }
39 else
40 {
41 boost::core::sp_thread_pause();
42 }
43}
44
45} // namespace detail
46
47} // namespace boost
48
49#endif // #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
50