diff --git a/include/boost/thread/detail/timespec.hpp b/include/boost/thread/detail/timespec.hpp index 270cb661..7a571774 100644 --- a/include/boost/thread/detail/timespec.hpp +++ b/include/boost/thread/detail/timespec.hpp @@ -137,7 +137,7 @@ namespace boost explicit real_timespec_timepoint(boost::intmax_t const& ns) : value(ns) {} #if defined BOOST_THREAD_USES_DATETIME - real_timespec_timepoint(boost::system_time const& abs_time) + explicit real_timespec_timepoint(boost::system_time const& abs_time) { boost::posix_time::time_duration const time_since_epoch = abs_time-boost::posix_time::from_time_t(0); value = timespec_duration(time_since_epoch).getNs(); @@ -145,7 +145,7 @@ namespace boost #endif #if defined BOOST_THREAD_USES_CHRONO template - real_timespec_timepoint(chrono::time_point const& abs_time) + explicit real_timespec_timepoint(chrono::time_point const& abs_time) { value = timespec_duration(abs_time.time_since_epoch()).getNs(); } @@ -208,7 +208,7 @@ namespace boost boost::intmax_t ns = ((((static_cast(ft.dwHighDateTime) << 32) | ft.dwLowDateTime) - 116444736000000000LL) * 100LL); return real_timespec_timepoint(ns); #elif defined(BOOST_THREAD_MACOS) - struct timeval tv; + timeval tv; ::gettimeofday(&tv, 0); timespec ts; ts.tv_sec = tv.tv_sec; @@ -235,7 +235,7 @@ namespace boost #if defined BOOST_THREAD_USES_CHRONO template - mono_timespec_timepoint(chrono::time_point const& abs_time); + explicit mono_timespec_timepoint(chrono::time_point const& abs_time); #endif #if defined BOOST_THREAD_PLATFORM_PTHREAD diff --git a/include/boost/thread/pthread/condition_variable.hpp b/include/boost/thread/pthread/condition_variable.hpp index 0064361f..b283b116 100644 --- a/include/boost/thread/pthread/condition_variable.hpp +++ b/include/boost/thread/pthread/condition_variable.hpp @@ -111,7 +111,7 @@ namespace boost #endif int cond_res; { - timespec const& ts = timeout.getTs(); + const timespec ts = timeout.getTs(); #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS thread_cv_detail::lock_on_exit > guard; detail::interruption_checker check_for_interruption(&internal_mutex,&cond); @@ -327,7 +327,7 @@ namespace boost lock_type& lock, const chrono::time_point& t) { - const boost::detail::internal_timespec_timepoint& ts = t; + const boost::detail::internal_timespec_timepoint ts(t); if (do_wait_until(lock, ts)) return cv_status::no_timeout; else return cv_status::timeout; } @@ -412,7 +412,7 @@ namespace boost boost::pthread::pthread_mutex_scoped_lock check_for_interruption(&internal_mutex); #endif guard.activate(m); - timespec const& ts = timeout.getTs(); + const timespec ts = timeout.getTs(); res=pthread_cond_timedwait(&cond,&internal_mutex,&ts); check_for_interruption.check(); guard.deactivate(); diff --git a/include/boost/thread/pthread/condition_variable_fwd.hpp b/include/boost/thread/pthread/condition_variable_fwd.hpp index bb8bab20..ee644b4d 100644 --- a/include/boost/thread/pthread/condition_variable_fwd.hpp +++ b/include/boost/thread/pthread/condition_variable_fwd.hpp @@ -236,7 +236,7 @@ namespace boost unique_lock& lock, const chrono::time_point& t) { - const detail::internal_timespec_timepoint& ts = t; + const detail::internal_timespec_timepoint ts(t); if (do_wait_until(lock, ts)) return cv_status::no_timeout; else return cv_status::timeout; } diff --git a/include/boost/thread/pthread/mutex.hpp b/include/boost/thread/pthread/mutex.hpp index 8896be21..4e116ac7 100644 --- a/include/boost/thread/pthread/mutex.hpp +++ b/include/boost/thread/pthread/mutex.hpp @@ -266,7 +266,7 @@ namespace boost // fixme: Shouldn't this functions be located on a .cpp file? bool do_try_lock_until(detail::internal_timespec_timepoint const &timeout) { - timespec const& ts = timeout.getTs(); + const timespec ts = timeout.getTs(); int const res=pthread_mutex_timedlock(&m,&ts); BOOST_ASSERT(!res || res==ETIMEDOUT); return !res; @@ -307,7 +307,7 @@ namespace boost bool do_try_lock_until(detail::internal_timespec_timepoint const &timeout) { boost::pthread::pthread_mutex_scoped_lock const local_lock(&m); - timespec const& ts = timeout.getTs(); + const timespec ts = timeout.getTs(); while(is_locked) { int const cond_res=pthread_cond_timedwait(&cond,&m,&ts); @@ -365,7 +365,7 @@ namespace boost template bool try_lock_until(const chrono::time_point& t) { - detail::internal_timespec_timepoint ts = t; + detail::internal_timespec_timepoint ts(t); return do_try_lock_until(ts); } #endif diff --git a/include/boost/thread/pthread/recursive_mutex.hpp b/include/boost/thread/pthread/recursive_mutex.hpp index 43fc235f..3a1f06ae 100644 --- a/include/boost/thread/pthread/recursive_mutex.hpp +++ b/include/boost/thread/pthread/recursive_mutex.hpp @@ -288,7 +288,7 @@ namespace boost // fixme: Shouldn't this functions be located on a .cpp file? bool do_try_lock_until(detail::internal_timespec_timepoint const &timeout) { - timespec const& ts = timeout.getTs(); + const timespec ts = timeout.getTs(); int const res=pthread_mutex_timedlock(&m,&ts); BOOST_ASSERT(!res || res==ETIMEDOUT); return !res; @@ -348,7 +348,7 @@ namespace boost ++count; return true; } - timespec const& ts = timeout.getTs(); + const timespec ts = timeout.getTs(); while(is_locked) { int const cond_res=pthread_cond_timedwait(&cond,&m,&ts); @@ -410,7 +410,7 @@ namespace boost template bool try_lock_until(const chrono::time_point& t) { - detail::internal_timespec_timepoint ts = t; + detail::internal_timespec_timepoint ts(t); return do_try_lock_until(ts); } #endif diff --git a/include/boost/thread/win32/condition_variable.hpp b/include/boost/thread/win32/condition_variable.hpp index d070a152..7509d40c 100644 --- a/include/boost/thread/win32/condition_variable.hpp +++ b/include/boost/thread/win32/condition_variable.hpp @@ -366,8 +366,8 @@ namespace boost { return true; } - const detail::internal_timespec_timepoint& ts = detail::internal_timespec_clock::now() - + detail::timespec_duration(wait_duration); + const detail::internal_timespec_timepoint ts = detail::internal_timespec_clock::now() + + detail::timespec_duration(wait_duration); return do_wait_until(m, ts); } @@ -401,8 +401,8 @@ namespace boost { return pred(); } - const detail::internal_timespec_timepoint& ts = detail::internal_timespec_clock::now() - + detail::timespec_duration(wait_duration); + const detail::internal_timespec_timepoint ts = detail::internal_timespec_clock::now() + + detail::timespec_duration(wait_duration); while (!pred()) { if(!do_wait_until(m, ts)) @@ -418,7 +418,7 @@ namespace boost unique_lock& lock, const chrono::time_point& t) { - const detail::internal_timespec_timepoint& ts = t; + const detail::internal_timespec_timepoint ts(t); if (do_wait_until(lock, ts)) return cv_status::no_timeout; else return cv_status::timeout; } @@ -535,8 +535,8 @@ namespace boost { return true; } - const detail::internal_timespec_timepoint& ts = detail::internal_timespec_clock::now() - + detail::timespec_duration(wait_duration); + const detail::internal_timespec_timepoint ts = detail::internal_timespec_clock::now() + + detail::timespec_duration(wait_duration); return do_wait_until(m, ts); } @@ -572,8 +572,8 @@ namespace boost { return pred(); } - const detail::internal_timespec_timepoint& ts = detail::internal_timespec_clock::now() - + detail::timespec_duration(wait_duration); + const detail::internal_timespec_timepoint ts = detail::internal_timespec_clock::now() + + detail::timespec_duration(wait_duration); while (!pred()) { if(!do_wait_until(m, ts)) @@ -589,7 +589,7 @@ namespace boost lock_type& lock, const chrono::time_point& t) { - const detail::internal_timespec_timepoint& ts = t; + const detail::internal_timespec_timepoint ts(t); if (do_wait_until(lock, ts)) return cv_status::no_timeout; else return cv_status::timeout; } diff --git a/include/boost/thread/win32/thread_data.hpp b/include/boost/thread/win32/thread_data.hpp index ecd31532..fdd8bae2 100644 --- a/include/boost/thread/win32/thread_data.hpp +++ b/include/boost/thread/win32/thread_data.hpp @@ -182,6 +182,8 @@ namespace boost void BOOST_THREAD_DECL yield() BOOST_NOEXCEPT; bool BOOST_THREAD_DECL interruptible_wait(detail::win32::handle handle_to_wait_for, detail::internal_timespec_timepoint const &timeout); + +#if defined BOOST_THREAD_USES_DATETIME template inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time) { @@ -198,10 +200,13 @@ namespace boost d = ts - detail::real_timespec_clock::now(); } } +#endif namespace no_interruption_point { bool BOOST_THREAD_DECL non_interruptible_wait(detail::win32::handle handle_to_wait_for, detail::internal_timespec_timepoint const &timeout); + +#if defined BOOST_THREAD_USES_DATETIME template inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time) { @@ -218,6 +223,7 @@ namespace boost d = ts - detail::real_timespec_clock::now(); } } +#endif } } diff --git a/src/pthread/thread.cpp b/src/pthread/thread.cpp index 9ae10994..c3a78772 100644 --- a/src/pthread/thread.cpp +++ b/src/pthread/thread.cpp @@ -439,7 +439,7 @@ namespace boost { // Use pthread_delay_np or nanosleep whenever possible here in the no_interruption_point // namespace because they do not provide an interruption point. - timespec const& ts2 = ts.getTs(); + const timespec ts2 = ts.getTs(); # if defined(BOOST_HAS_PTHREAD_DELAY_NP) # if defined(__IBMCPP__) || defined(_AIX) BOOST_VERIFY(!pthread_delay_np(const_cast(&ts2))); @@ -450,7 +450,7 @@ namespace boost nanosleep(&ts2, 0); # else // Fall back to using a condition variable even though it does provide an interruption point. - const detail::internal_timespec_timepoint& ts2 = detail::internal_timespec_clock::now() + ts; + const detail::internal_timespec_timepoint ts2 = detail::internal_timespec_clock::now() + ts; mutex mx; unique_lock lock(mx); condition_variable cond; @@ -478,7 +478,7 @@ namespace boost d = ts2 - detail::mono_timespec_clock::now(); } #else - const detail::internal_timespec_timepoint& ts2 = detail::internal_timespec_clock::now() + ts; + const detail::internal_timespec_timepoint ts2 = detail::internal_timespec_clock::now() + ts; while (cond.do_wait_until(lock, ts2)) {} #endif }