From 66890c3f3d16c6da4aca31a6d824b0a24f5ec257 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 18 Jun 2023 21:54:13 +0300 Subject: [PATCH] Use SwitchToThread instead of Sleep(0) is sp_thread_yield; the general consensus is that it's newer and 'smarter' --- include/boost/core/detail/sp_thread_yield.hpp | 4 ++-- include/boost/core/detail/sp_win32_sleep.hpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/boost/core/detail/sp_thread_yield.hpp b/include/boost/core/detail/sp_thread_yield.hpp index efe6ea0..25127e8 100644 --- a/include/boost/core/detail/sp_thread_yield.hpp +++ b/include/boost/core/detail/sp_thread_yield.hpp @@ -24,7 +24,7 @@ #if defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) #if defined(BOOST_SP_REPORT_IMPLEMENTATION) - BOOST_PRAGMA_MESSAGE("Using Sleep(0) in sp_thread_yield") + BOOST_PRAGMA_MESSAGE("Using SwitchToThread() in sp_thread_yield") #endif #include @@ -38,7 +38,7 @@ namespace detail inline void sp_thread_yield() BOOST_NOEXCEPT { - Sleep( 0 ); + SwitchToThread(); } } // namespace detail diff --git a/include/boost/core/detail/sp_win32_sleep.hpp b/include/boost/core/detail/sp_win32_sleep.hpp index df51292..adec53e 100644 --- a/include/boost/core/detail/sp_win32_sleep.hpp +++ b/include/boost/core/detail/sp_win32_sleep.hpp @@ -41,6 +41,8 @@ namespace detail extern "C" __declspec(dllimport) void BOOST_CORE_SP_STDCALL Sleep( unsigned long ms ); #endif +extern "C" __declspec(dllimport) int BOOST_CORE_SP_STDCALL SwitchToThread(); + #undef BOOST_CORE_SP_STDCALL #endif // !defined( BOOST_USE_WINDOWS_H )