1 #ifndef BOOST_SMART_PTR_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED 2 #define BOOST_SMART_PTR_DETAIL_SP_THREAD_SLEEP_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/sp_thread_sleep.hpp 11 // 12 // inline void bost::detail::sp_thread_sleep(); 13 // 14 // Cease execution for a while to yield to other threads, 15 // as if by calling nanosleep() with an appropriate interval. 16 // 17 // Copyright 2008, 2020 Peter Dimov 18 // Distributed under the Boost Software License, Version 1.0 19 // https://www.boost.org/LICENSE_1_0.txt 20 21 #include <boost/config.hpp> 22 #include <boost/config/pragma_message.hpp> 23 24 #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ ) 25 26 #if defined(BOOST_SP_REPORT_IMPLEMENTATION) 27 BOOST_PRAGMA_MESSAGE("Using Sleep(1) in sp_thread_sleep") 28 #endif 29 30 #include <boost/smart_ptr/detail/sp_win32_sleep.hpp> 31 32 namespace boost 33 { 34 35 namespace detail 36 { 37 sp_thread_sleep()38inline void sp_thread_sleep() 39 { 40 Sleep( 1 ); 41 } 42 43 } // namespace detail 44 45 } // namespace boost 46 47 #elif defined(BOOST_HAS_NANOSLEEP) 48 49 #if defined(BOOST_SP_REPORT_IMPLEMENTATION) 50 BOOST_PRAGMA_MESSAGE("Using nanosleep() in sp_thread_sleep") 51 #endif 52 53 #include <time.h> 54 55 namespace boost 56 { 57 58 namespace detail 59 { 60 sp_thread_sleep()61inline void sp_thread_sleep() 62 { 63 // g++ -Wextra warns on {} or {0} 64 struct timespec rqtp = { 0, 0 }; 65 66 // POSIX says that timespec has tv_sec and tv_nsec 67 // But it doesn't guarantee order or placement 68 69 rqtp.tv_sec = 0; 70 rqtp.tv_nsec = 1000; 71 72 nanosleep( &rqtp, 0 ); 73 } 74 75 } // namespace detail 76 77 } // namespace boost 78 79 #else 80 81 #if defined(BOOST_SP_REPORT_IMPLEMENTATION) 82 BOOST_PRAGMA_MESSAGE("Using sp_thread_yield() in sp_thread_sleep") 83 #endif 84 85 #include <boost/smart_ptr/detail/sp_thread_yield.hpp> 86 87 namespace boost 88 { 89 90 namespace detail 91 { 92 sp_thread_sleep()93inline void sp_thread_sleep() 94 { 95 sp_thread_yield(); 96 } 97 98 } // namespace detail 99 100 } // namespace boost 101 102 #endif 103 104 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_THREAD_SLEEP_HPP_INCLUDED 105