diff --git a/include/boost/thread/v2/thread.hpp b/include/boost/thread/v2/thread.hpp index 68e827dc..299152b5 100644 --- a/include/boost/thread/v2/thread.hpp +++ b/include/boost/thread/v2/thread.hpp @@ -43,10 +43,10 @@ namespace boost { Duration d100 = (std::min)(d, Duration(milliseconds(100))); sleep_until(thread_detail::internal_clock_t::now() + ceil(d100)); - Duration d = t - Clock::now(); + d = t - Clock::now(); } } -#ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY +#if defined BOOST_THREAD_SLEEP_FOR_IS_STEADY && !defined BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC template void sleep_for(const chrono::duration& d) @@ -58,12 +58,12 @@ namespace boost nanoseconds ns; if (d < Max) { - ns = duration_cast(d); - if (ns < d) - ++ns; + ns = ceil(d); } else + { ns = nanoseconds:: max BOOST_PREVENT_MACRO_SUBSTITUTION (); + } sleep_for(ns); } } @@ -117,7 +117,7 @@ namespace boost } } -#if defined BOOST_THREAD_SLEEP_FOR_IS_STEADY +#if defined BOOST_THREAD_SLEEP_FOR_IS_STEADY && !defined BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC template void sleep_for(const chrono::duration& d) @@ -125,18 +125,17 @@ namespace boost using namespace chrono; if (d > duration::zero()) { - const duration Max = nanoseconds::max BOOST_PREVENT_MACRO_SUBSTITUTION (); + const duration Max = (nanoseconds::max)(); nanoseconds ns; if (d < Max) { - // fixme: ceil? - ns = duration_cast(d); - if (ns < d) - ++ns; + ns = ceil(d); } else + { // fixme: it is normal to sleep less than requested? Shouldn't we need to iterate until d has been elapsed? - ns = nanoseconds:: max BOOST_PREVENT_MACRO_SUBSTITUTION (); + ns = (nanoseconds::max)(); + } sleep_for(ns); } } diff --git a/src/pthread/thread.cpp b/src/pthread/thread.cpp index 186024d3..41aa7ced 100644 --- a/src/pthread/thread.cpp +++ b/src/pthread/thread.cpp @@ -435,10 +435,8 @@ namespace boost void BOOST_THREAD_DECL sleep_for(const detail::timespec_duration& ts) { - if (ts >= detail::timespec_duration::zero()) + if (ts > detail::timespec_duration::zero()) { - - # if defined(BOOST_HAS_PTHREAD_DELAY_NP) && !defined(BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC) # if defined(__IBMCPP__) || defined(_AIX) BOOST_VERIFY(!pthread_delay_np(const_cast(&ts.get()))); @@ -463,7 +461,6 @@ namespace boost { for (int foo=0; foo < 5; ++foo) { - # if defined(BOOST_HAS_PTHREAD_DELAY_NP) detail::timespec_duration d = ts - now; BOOST_VERIFY(!pthread_delay_np(&d.get()));