Files
boost_smart_ptr/include/boost/smart_ptr/detail/yield_k.hpp

52 lines
1.1 KiB
C++
Raw Normal View History

#ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
#define BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED
2008-03-27 22:20:11 +00:00
// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif
2020-06-10 18:58:08 +03:00
// boost/smart_ptr/detail/yield_k.hpp
2008-03-27 22:20:11 +00:00
//
2020-06-10 18:58:08 +03:00
// Copyright 2008, 2020 Peter Dimov
2008-03-27 22:20:11 +00:00
//
2020-06-10 18:58:08 +03:00
// inline void boost::detail::yield( unsigned k );
2008-03-27 22:20:11 +00:00
//
2020-06-10 18:58:08 +03:00
// Typical use:
// for( unsigned k = 0; !try_lock(); ++k ) yield( k );
2008-03-27 22:20:11 +00:00
//
2020-06-10 18:58:08 +03:00
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
2008-03-27 22:20:11 +00:00
2020-06-10 18:58:08 +03:00
#include <boost/smart_ptr/detail/sp_thread_pause.hpp>
#include <boost/smart_ptr/detail/sp_thread_sleep.hpp>
2008-03-27 22:20:11 +00:00
#include <boost/config.hpp>
2020-06-07 20:40:41 +03:00
namespace boost
{
namespace detail
{
2020-06-10 18:58:08 +03:00
inline void yield( unsigned k )
2020-06-07 20:40:41 +03:00
{
2020-06-10 18:58:08 +03:00
// Experiments on Windows and Fedora 32 show that a single pause,
// followed by an immediate sp_thread_sleep(), is best.
2020-06-10 18:58:08 +03:00
if( k == 0 )
2020-06-07 20:40:41 +03:00
{
2020-06-10 18:58:08 +03:00
sp_thread_pause();
2020-06-07 20:40:41 +03:00
}
else
{
sp_thread_sleep();
}
}
} // namespace detail
} // namespace boost
#endif // #ifndef BOOST_SMART_PTR_DETAIL_YIELD_K_HPP_INCLUDED