Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:28

0001 #ifndef BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED
0002 #define BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED
0003 
0004 // MS compatible compilers support #pragma once
0005 
0006 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0007 # pragma once
0008 #endif
0009 
0010 // boost/core/detail/sp_thread_sleep.hpp
0011 //
0012 // inline void bost::core::sp_thread_sleep();
0013 //
0014 //   Cease execution for a while to yield to other threads,
0015 //   as if by calling nanosleep() with an appropriate interval.
0016 //
0017 // Copyright 2008, 2020, 2023 Peter Dimov
0018 // Distributed under the Boost Software License, Version 1.0
0019 // https://www.boost.org/LICENSE_1_0.txt
0020 
0021 #include <boost/config.hpp>
0022 #include <boost/config/pragma_message.hpp>
0023 
0024 #if defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
0025 
0026 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0027   BOOST_PRAGMA_MESSAGE("Using Sleep(1) in sp_thread_sleep")
0028 #endif
0029 
0030 #include <boost/core/detail/sp_win32_sleep.hpp>
0031 
0032 namespace boost
0033 {
0034 namespace core
0035 {
0036 namespace detail
0037 {
0038 
0039 inline void sp_thread_sleep() BOOST_NOEXCEPT
0040 {
0041     Sleep( 1 );
0042 }
0043 
0044 } // namespace detail
0045 
0046 using boost::core::detail::sp_thread_sleep;
0047 
0048 } // namespace core
0049 } // namespace boost
0050 
0051 #elif defined(BOOST_HAS_NANOSLEEP)
0052 
0053 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0054   BOOST_PRAGMA_MESSAGE("Using nanosleep() in sp_thread_sleep")
0055 #endif
0056 
0057 #include <time.h>
0058 
0059 #if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__)
0060 # include <pthread.h>
0061 #endif
0062 
0063 namespace boost
0064 {
0065 namespace core
0066 {
0067 
0068 inline void sp_thread_sleep() BOOST_NOEXCEPT
0069 {
0070 #if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__)
0071 
0072     int oldst;
0073     pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &oldst );
0074 
0075 #endif
0076 
0077     // g++ -Wextra warns on {} or {0}
0078     struct timespec rqtp = { 0, 0 };
0079 
0080     // POSIX says that timespec has tv_sec and tv_nsec
0081     // But it doesn't guarantee order or placement
0082 
0083     rqtp.tv_sec = 0;
0084     rqtp.tv_nsec = 1000;
0085 
0086     nanosleep( &rqtp, 0 );
0087 
0088 #if defined(BOOST_HAS_PTHREADS) && !defined(__ANDROID__)
0089 
0090     pthread_setcancelstate( oldst, &oldst );
0091 
0092 #endif
0093 
0094 }
0095 
0096 } // namespace core
0097 } // namespace boost
0098 
0099 #else
0100 
0101 #if defined(BOOST_SP_REPORT_IMPLEMENTATION)
0102   BOOST_PRAGMA_MESSAGE("Using sp_thread_yield() in sp_thread_sleep")
0103 #endif
0104 
0105 #include <boost/core/detail/sp_thread_yield.hpp>
0106 
0107 namespace boost
0108 {
0109 namespace core
0110 {
0111 
0112 inline void sp_thread_sleep() BOOST_NOEXCEPT
0113 {
0114     sp_thread_yield();
0115 }
0116 
0117 } // namespace core
0118 } // namespace boost
0119 
0120 #endif
0121 
0122 #endif // #ifndef BOOST_CORE_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED