From 23ef6d35316be0dfc4e110e701f2fccdeae94eec Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 2 Jun 2023 03:57:38 +0300 Subject: [PATCH] Disable cancelation around nanosleep in sp_thread_sleep --- include/boost/core/detail/sp_thread_sleep.hpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/include/boost/core/detail/sp_thread_sleep.hpp b/include/boost/core/detail/sp_thread_sleep.hpp index d18da23..0d26c83 100644 --- a/include/boost/core/detail/sp_thread_sleep.hpp +++ b/include/boost/core/detail/sp_thread_sleep.hpp @@ -14,7 +14,7 @@ // Cease execution for a while to yield to other threads, // as if by calling nanosleep() with an appropriate interval. // -// Copyright 2008, 2020 Peter Dimov +// Copyright 2008, 2020, 2023 Peter Dimov // Distributed under the Boost Software License, Version 1.0 // https://www.boost.org/LICENSE_1_0.txt @@ -56,6 +56,10 @@ using boost::core::detail::sp_thread_sleep; #include +#if defined(BOOST_HAS_PTHREADS) +# include +#endif + namespace boost { namespace core @@ -63,6 +67,13 @@ namespace core inline void sp_thread_sleep() { +#if defined(BOOST_HAS_PTHREADS) + + int oldst; + pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldst ); + +#endif + // g++ -Wextra warns on {} or {0} struct timespec rqtp = { 0, 0 }; @@ -73,6 +84,13 @@ inline void sp_thread_sleep() rqtp.tv_nsec = 1000; nanosleep( &rqtp, 0 ); + +#if defined(BOOST_HAS_PTHREADS) + + pthread_setcancelstate( oldst, &oldst ); + +#endif + } } // namespace core