diff --git a/include/boost/thread/detail/internal_clock.hpp b/include/boost/thread/detail/internal_clock.hpp deleted file mode 100644 index 5ea6d34c..00000000 --- a/include/boost/thread/detail/internal_clock.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2017 -// Vicente J. Botet Escriba -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// - -#ifndef BOOST_THREAD_DETAIL_INTERNAL_CLOCK_HPP -#define BOOST_THREAD_DETAIL_INTERNAL_CLOCK_HPP - -#include -#ifdef BOOST_THREAD_USES_CHRONO -#include -#endif - -#include - -namespace boost { -namespace thread_detail { - - #ifdef BOOST_THREAD_USES_CHRONO - #ifdef BOOST_THREAD_INTERNAL_CLOCK_IS_MONO - typedef chrono::steady_clock internal_clock_t; - #else - typedef chrono::system_clock internal_clock_t; - #endif - #endif - -} // namespace thread_detail -} // namespace boost - -#include - -#endif // header diff --git a/include/boost/thread/detail/thread.hpp b/include/boost/thread/detail/thread.hpp index d8e884fe..20329398 100644 --- a/include/boost/thread/detail/thread.hpp +++ b/include/boost/thread/detail/thread.hpp @@ -37,7 +37,6 @@ #include #include #ifdef BOOST_THREAD_USES_CHRONO -#include #include #include #endif @@ -478,16 +477,14 @@ namespace boost template bool try_join_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d < CD::zero() ) return false; // d == zero() is valid - d = (std::min)(d, CD(milliseconds(100))); - while ( ! try_join_until(thread_detail::internal_clock_t::now() + d) ) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while ( ! try_join_until(detail::internal_chrono_clock::now() + d) ) { d = t - Clock::now(); if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return true; } @@ -517,7 +514,7 @@ namespace boost #endif #ifdef BOOST_THREAD_USES_CHRONO template - bool try_join_until(const chrono::time_point& t) + bool try_join_until(const chrono::time_point& t) { return do_try_join_until(boost::detail::internal_timespec_timepoint(t)); } @@ -529,7 +526,6 @@ namespace boost inline bool timed_join(TimeDuration const& rel_time) { detail::timespec_duration d(rel_time); - if ( d < detail::timespec_duration::zero() ) return false; // d == zero() is valid #if defined(BOOST_THREAD_HAS_MONO_CLOCK) && !defined(BOOST_THREAD_INTERNAL_CLOCK_IS_MONO) const detail::mono_timespec_timepoint& ts = detail::mono_timespec_clock::now() + d; d = (std::min)(d, detail::timespec_milliseconds(100)); diff --git a/include/boost/thread/pthread/timespec.hpp b/include/boost/thread/detail/timespec.hpp similarity index 83% rename from include/boost/thread/pthread/timespec.hpp rename to include/boost/thread/detail/timespec.hpp index 4417b24a..270cb661 100644 --- a/include/boost/thread/pthread/timespec.hpp +++ b/include/boost/thread/detail/timespec.hpp @@ -1,5 +1,5 @@ -#ifndef BOOST_THREAD_PTHREAD_TIMESPEC_HPP -#define BOOST_THREAD_PTHREAD_TIMESPEC_HPP +#ifndef BOOST_THREAD_DETAIL_TIMESPEC_HPP +#define BOOST_THREAD_DETAIL_TIMESPEC_HPP // (C) Copyright 2007-8 Anthony Williams // (C) Copyright 2012 Vicente J. Botet Escriba // @@ -31,17 +31,19 @@ #include // for clock_gettime #endif +#include + #include namespace boost { namespace detail { - +#if defined BOOST_THREAD_PLATFORM_PTHREAD inline timespec ns_to_timespec(boost::intmax_t const& ns) { boost::intmax_t s = ns / 1000000000l; - struct timespec ts; + timespec ts; ts.tv_sec = static_cast (s); ts.tv_nsec = static_cast (ns - s * 1000000000l); return ts; @@ -50,59 +52,53 @@ namespace boost { return static_cast(ts.tv_sec) * 1000000000l + ts.tv_nsec; } +#endif class timespec_duration { public: - explicit timespec_duration(timespec const& v) : value(v) {} - explicit timespec_duration(boost::intmax_t const& ns) : value(ns_to_timespec(ns)) {} + explicit timespec_duration(boost::intmax_t const& ns) : value(ns) {} #if defined BOOST_THREAD_USES_DATETIME timespec_duration(boost::posix_time::time_duration const& rel_time) { - struct timespec d = { 0,0}; - d.tv_sec=rel_time.total_seconds(); - d.tv_nsec=(long)(rel_time.fractional_seconds()*(1000000000l/rel_time.ticks_per_second())); - value = d; + value = static_cast(rel_time.total_seconds()) * 1000000000l; + value += rel_time.fractional_seconds() * (1000000000l / rel_time.ticks_per_second()); } #endif #if defined BOOST_THREAD_USES_CHRONO template timespec_duration(chrono::duration const& d) { - value.tv_sec = static_cast(chrono::duration_cast(d).count()); - value.tv_nsec = static_cast((chrono::ceil(d) - chrono::duration_cast(d)).count()); + value = chrono::ceil(d).count(); } #endif - timespec& get() { return value; } - timespec const& get() const { return value; } - boost::intmax_t getNs() const { return timespec_to_ns(value); } +#if defined BOOST_THREAD_PLATFORM_PTHREAD + inline timespec getTs() const { return ns_to_timespec(value); } +#endif + inline boost::intmax_t getNs() const { return value; } inline boost::intmax_t getMs() const { - const boost::intmax_t& ns = timespec_to_ns(value); // ceil/floor away from zero - if (ns >= 0) + if (value >= 0) { // return ceiling of positive numbers - return (ns + 999999) / 1000000; + return (value + 999999) / 1000000; } else { // return floor of negative numbers - return (ns - 999999) / 1000000; + return (value - 999999) / 1000000; } } static inline timespec_duration zero() { - timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = 0; - return timespec_duration(ts); + return timespec_duration(0); } private: - timespec value; + boost::intmax_t value; }; inline bool operator==(timespec_duration const& lhs, timespec_duration const& rhs) @@ -138,30 +134,30 @@ namespace boost class real_timespec_timepoint { public: - explicit real_timespec_timepoint(timespec const& v) : value(v) {} - explicit real_timespec_timepoint(boost::intmax_t const& ns) : value(ns_to_timespec(ns)) {} + 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) { boost::posix_time::time_duration const time_since_epoch = abs_time-boost::posix_time::from_time_t(0); - value = timespec_duration(time_since_epoch).get(); + value = timespec_duration(time_since_epoch).getNs(); } #endif #if defined BOOST_THREAD_USES_CHRONO template real_timespec_timepoint(chrono::time_point const& abs_time) { - value = timespec_duration(abs_time.time_since_epoch()).get(); + value = timespec_duration(abs_time.time_since_epoch()).getNs(); } #endif - inline timespec& get() { return value; } - inline timespec const& get() const { return value; } - inline boost::intmax_t getNs() const { return timespec_to_ns(value); } +#if defined BOOST_THREAD_PLATFORM_PTHREAD + inline timespec getTs() const { return ns_to_timespec(value); } +#endif + inline boost::intmax_t getNs() const { return value; } private: - timespec value; + boost::intmax_t value; }; inline bool operator==(real_timespec_timepoint const& lhs, real_timespec_timepoint const& rhs) @@ -212,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) - timeval tv; + struct timeval tv; ::gettimeofday(&tv, 0); timespec ts; ts.tv_sec = tv.tv_sec; @@ -225,7 +221,7 @@ namespace boost BOOST_ASSERT(0 && "Boost::Thread - clock_gettime(CLOCK_REALTIME) Internal Error"); return real_timespec_timepoint(0); } - return real_timespec_timepoint(ts); + return real_timespec_timepoint(timespec_to_ns(ts)); #endif } }; @@ -235,29 +231,27 @@ namespace boost class mono_timespec_timepoint { public: - explicit mono_timespec_timepoint(timespec const& v) : value(v) {} - explicit mono_timespec_timepoint(boost::intmax_t const& ns) : value(ns_to_timespec(ns)) {} + explicit mono_timespec_timepoint(boost::intmax_t const& ns) : value(ns) {} #if defined BOOST_THREAD_USES_CHRONO template mono_timespec_timepoint(chrono::time_point const& abs_time); #endif - inline timespec& get() { return value; } - inline timespec const& get() const { return value; } - inline boost::intmax_t getNs() const { return timespec_to_ns(value); } +#if defined BOOST_THREAD_PLATFORM_PTHREAD + inline timespec getTs() const { return ns_to_timespec(value); } +#endif + inline boost::intmax_t getNs() const { return value; } - // can't use max() since that is a macro on some Windows systems + // can't name this max() since that is a macro on some Windows systems static inline mono_timespec_timepoint getMax() { - timespec ts; - ts.tv_sec = 0x7fffffff; - ts.tv_nsec = 0x7fffffff; - return mono_timespec_timepoint(ts); + boost::intmax_t ns = (std::numeric_limits::max)(); + return mono_timespec_timepoint(ns); } private: - timespec value; + boost::intmax_t value; }; inline bool operator==(mono_timespec_timepoint const& lhs, mono_timespec_timepoint const& rhs) @@ -350,7 +344,7 @@ namespace boost BOOST_ASSERT(0 && "Boost::Thread - clock_gettime(CLOCK_MONOTONIC) Internal Error"); return mono_timespec_timepoint(0); } - return mono_timespec_timepoint(ts); + return mono_timespec_timepoint(timespec_to_ns(ts)); #endif } }; @@ -361,7 +355,7 @@ namespace boost { // This conversion assumes that chrono::steady_clock::now() and // mono_timespec_clock::now() share the same epoch. - value = timespec_duration(abs_time.time_since_epoch()).get(); + value = timespec_duration(abs_time.time_since_epoch()).getNs(); } #endif @@ -375,6 +369,14 @@ namespace boost typedef real_timespec_timepoint internal_timespec_timepoint; #endif +#ifdef BOOST_THREAD_USES_CHRONO +#ifdef BOOST_THREAD_INTERNAL_CLOCK_IS_MONO + typedef chrono::steady_clock internal_chrono_clock; +#else + typedef chrono::system_clock internal_chrono_clock; +#endif +#endif + } } diff --git a/include/boost/thread/future.hpp b/include/boost/thread/future.hpp index 5db3851b..448fec95 100644 --- a/include/boost/thread/future.hpp +++ b/include/boost/thread/future.hpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -39,7 +38,7 @@ #include #include -#include +#include #if defined BOOST_THREAD_FUTURE_USES_OPTIONAL #include diff --git a/include/boost/thread/pthread/condition_variable.hpp b/include/boost/thread/pthread/condition_variable.hpp index 881e4917..0064361f 100644 --- a/include/boost/thread/pthread/condition_variable.hpp +++ b/include/boost/thread/pthread/condition_variable.hpp @@ -6,7 +6,7 @@ // (C) Copyright 2007-10 Anthony Williams // (C) Copyright 2011-2012 Vicente J. Botet Escriba -#include +#include #include #include @@ -15,7 +15,6 @@ #endif #include #ifdef BOOST_THREAD_USES_CHRONO -#include #include #include #endif @@ -112,17 +111,18 @@ namespace boost #endif int cond_res; { + timespec const& 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); pthread_mutex_t* the_mutex = &internal_mutex; guard.activate(m); - cond_res=pthread_cond_timedwait(&cond,the_mutex,&timeout.get()); + cond_res=pthread_cond_timedwait(&cond,the_mutex,&ts); check_for_interruption.check(); guard.deactivate(); #else pthread_mutex_t* the_mutex = m.mutex()->native_handle(); - cond_res=pthread_cond_timedwait(&cond,the_mutex,&timeout.get()); + cond_res=pthread_cond_timedwait(&cond,the_mutex,ts); #endif } #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS @@ -325,7 +325,7 @@ namespace boost cv_status wait_until( lock_type& lock, - const chrono::time_point& t) + const chrono::time_point& t) { const boost::detail::internal_timespec_timepoint& ts = t; if (do_wait_until(lock, ts)) return cv_status::no_timeout; @@ -338,16 +338,14 @@ namespace boost lock_type& lock, const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return cv_status::timeout; - d = (std::min)(d, CD(milliseconds(100))); - while (cv_status::timeout == wait_until(lock, thread_detail::internal_clock_t::now() + d)) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while (cv_status::timeout == wait_until(lock, detail::internal_chrono_clock::now() + d)) { d = t - Clock::now(); if ( d <= CD::zero() ) return cv_status::timeout; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return cv_status::no_timeout; } @@ -414,7 +412,8 @@ namespace boost boost::pthread::pthread_mutex_scoped_lock check_for_interruption(&internal_mutex); #endif guard.activate(m); - res=pthread_cond_timedwait(&cond,&internal_mutex,&timeout.get()); + timespec const& 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 0a8f9941..bb8bab20 100644 --- a/include/boost/thread/pthread/condition_variable_fwd.hpp +++ b/include/boost/thread/pthread/condition_variable_fwd.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #if defined BOOST_THREAD_USES_DATETIME @@ -21,7 +21,6 @@ #endif #ifdef BOOST_THREAD_USES_CHRONO -#include #include #include #endif @@ -235,7 +234,7 @@ namespace boost cv_status wait_until( unique_lock& lock, - const chrono::time_point& t) + const chrono::time_point& t) { const detail::internal_timespec_timepoint& ts = t; if (do_wait_until(lock, ts)) return cv_status::no_timeout; @@ -248,16 +247,14 @@ namespace boost unique_lock& lock, const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return cv_status::timeout; - d = (std::min)(d, CD(milliseconds(100))); - while (cv_status::timeout == wait_until(lock, thread_detail::internal_clock_t::now() + d)) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while (cv_status::timeout == wait_until(lock, detail::internal_chrono_clock::now() + d)) { d = t - Clock::now(); if ( d <= CD::zero() ) return cv_status::timeout; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return cv_status::no_timeout; } diff --git a/include/boost/thread/pthread/mutex.hpp b/include/boost/thread/pthread/mutex.hpp index 1dfb96cc..8896be21 100644 --- a/include/boost/thread/pthread/mutex.hpp +++ b/include/boost/thread/pthread/mutex.hpp @@ -21,11 +21,10 @@ #endif #include #include -#include +#include #include #include #ifdef BOOST_THREAD_USES_CHRONO -#include #include #include #endif @@ -267,7 +266,8 @@ namespace boost // fixme: Shouldn't this functions be located on a .cpp file? bool do_try_lock_until(detail::internal_timespec_timepoint const &timeout) { - int const res=pthread_mutex_timedlock(&m,&timeout.get()); + timespec const& ts = timeout.getTs(); + int const res=pthread_mutex_timedlock(&m,&ts); BOOST_ASSERT(!res || res==ETIMEDOUT); return !res; } @@ -307,9 +307,10 @@ 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(); while(is_locked) { - int const cond_res=pthread_cond_timedwait(&cond,&m,&timeout.get()); + int const cond_res=pthread_cond_timedwait(&cond,&m,&ts); if(cond_res==ETIMEDOUT) { return false; @@ -350,21 +351,19 @@ namespace boost template bool try_lock_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); - while ( ! try_lock_until(thread_detail::internal_clock_t::now() + d)) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while ( ! try_lock_until(detail::internal_chrono_clock::now() + d)) { d = t - Clock::now(); if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return true; } template - bool try_lock_until(const chrono::time_point& t) + bool try_lock_until(const chrono::time_point& t) { detail::internal_timespec_timepoint ts = t; return do_try_lock_until(ts); diff --git a/include/boost/thread/pthread/recursive_mutex.hpp b/include/boost/thread/pthread/recursive_mutex.hpp index 3f9b9500..43fc235f 100644 --- a/include/boost/thread/pthread/recursive_mutex.hpp +++ b/include/boost/thread/pthread/recursive_mutex.hpp @@ -19,11 +19,10 @@ #endif #include #include -#include +#include #include #include #ifdef BOOST_THREAD_USES_CHRONO -#include #include #include #endif @@ -289,7 +288,8 @@ namespace boost // fixme: Shouldn't this functions be located on a .cpp file? bool do_try_lock_until(detail::internal_timespec_timepoint const &timeout) { - int const res=pthread_mutex_timedlock(&m,&timeout.get()); + timespec const& ts = timeout.getTs(); + int const res=pthread_mutex_timedlock(&m,&ts); BOOST_ASSERT(!res || res==ETIMEDOUT); return !res; } @@ -348,9 +348,10 @@ namespace boost ++count; return true; } + timespec const& ts = timeout.getTs(); while(is_locked) { - int const cond_res=pthread_cond_timedwait(&cond,&m,&timeout.get()); + int const cond_res=pthread_cond_timedwait(&cond,&m,&ts); if(cond_res==ETIMEDOUT) { return false; @@ -394,22 +395,20 @@ namespace boost template bool try_lock_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); - while ( ! try_lock_until(thread_detail::internal_clock_t::now() + d)) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while ( ! try_lock_until(detail::internal_chrono_clock::now() + d)) { d = t - Clock::now(); if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return true; } template - bool try_lock_until(const chrono::time_point& t) + bool try_lock_until(const chrono::time_point& t) { detail::internal_timespec_timepoint ts = t; return do_try_lock_until(ts); diff --git a/include/boost/thread/pthread/shared_mutex.hpp b/include/boost/thread/pthread/shared_mutex.hpp index fe328fac..1b056912 100644 --- a/include/boost/thread/pthread/shared_mutex.hpp +++ b/include/boost/thread/pthread/shared_mutex.hpp @@ -20,8 +20,7 @@ #include #endif #include -#include -#include +#include #include @@ -260,23 +259,21 @@ namespace boost return try_lock_shared_until(chrono::steady_clock::now() + rel_time); } template - bool try_lock_shared_until(const chrono::time_point& t) + bool try_lock_shared_until(const chrono::time_point& t) { return do_try_lock_shared_until(boost::detail::internal_timespec_timepoint(t)); } template bool try_lock_shared_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); - while ( ! try_lock_shared_until(thread_detail::internal_clock_t::now() + d) ) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while ( ! try_lock_shared_until(detail::internal_chrono_clock::now() + d) ) { d = t - Clock::now(); if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return true; } @@ -468,23 +465,21 @@ namespace boost return try_lock_until(chrono::steady_clock::now() + rel_time); } template - bool try_lock_until(const chrono::time_point& t) + bool try_lock_until(const chrono::time_point& t) { return do_try_lock_until(boost::detail::internal_timespec_timepoint(t)); } template bool try_lock_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); - while ( ! try_lock_until(thread_detail::internal_clock_t::now() + d) ) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while ( ! try_lock_until(detail::internal_chrono_clock::now() + d) ) { d = t - Clock::now(); if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return true; } @@ -584,23 +579,21 @@ namespace boost return try_lock_upgrade_until(chrono::steady_clock::now() + rel_time); } template - bool try_lock_upgrade_until(const chrono::time_point& t) + bool try_lock_upgrade_until(const chrono::time_point& t) { return do_try_lock_upgrade_until(boost::detail::internal_timespec_timepoint(t)); } template bool try_lock_upgrade_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); - while ( ! try_lock_upgrade_until(thread_detail::internal_clock_t::now() + d) ) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while ( ! try_lock_upgrade_until(detail::internal_chrono_clock::now() + d) ) { d = t - Clock::now(); if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return true; } @@ -691,23 +684,21 @@ namespace boost return try_unlock_upgrade_and_lock_until(chrono::steady_clock::now() + rel_time); } template - bool try_unlock_upgrade_and_lock_until(const chrono::time_point& t) + bool try_unlock_upgrade_and_lock_until(const chrono::time_point& t) { return do_try_unlock_upgrade_and_lock_until(boost::detail::internal_timespec_timepoint(t)); } template bool try_unlock_upgrade_and_lock_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); - while ( ! try_unlock_upgrade_and_lock_until(thread_detail::internal_clock_t::now() + d) ) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while ( ! try_unlock_upgrade_and_lock_until(detail::internal_chrono_clock::now() + d) ) { d = t - Clock::now(); if ( d <= CD::zero() ) return false; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return true; } diff --git a/include/boost/thread/v2/shared_mutex.hpp b/include/boost/thread/v2/shared_mutex.hpp index 8af14279..1a4bdd6a 100644 --- a/include/boost/thread/v2/shared_mutex.hpp +++ b/include/boost/thread/v2/shared_mutex.hpp @@ -156,7 +156,6 @@ public: #include #include #include -#include #define BOOST_THREAD_INLINE inline namespace boost { diff --git a/include/boost/thread/v2/thread.hpp b/include/boost/thread/v2/thread.hpp index a5cf7c48..1d6b7d6e 100644 --- a/include/boost/thread/v2/thread.hpp +++ b/include/boost/thread/v2/thread.hpp @@ -13,7 +13,6 @@ #endif #include #include -#include namespace boost { @@ -32,19 +31,17 @@ namespace boost template void sleep_until(const chrono::time_point& t) { - using namespace chrono; - sleep_for(t - steady_clock::now()); + sleep_for(t - chrono::steady_clock::now()); } template void sleep_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); while (d > CD::zero()) { - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); sleep_for(d); d = t - Clock::now(); } @@ -55,17 +52,15 @@ namespace boost template void sleep_for(const chrono::duration& d) { - using namespace chrono; - if (d > duration::zero()) + if (d > chrono::duration::zero()) { - sleep_until(steady_clock::now() + d); + sleep_until(chrono::steady_clock::now() + d); } } template - void sleep_until(const chrono::time_point& t) + void sleep_until(const chrono::time_point& t) { - using namespace chrono; mutex mut; condition_variable cv; unique_lock lk(mut); @@ -75,13 +70,12 @@ namespace boost template void sleep_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); while (d > CD::zero()) { - d = (std::min)(d, CD(milliseconds(100))); - sleep_until(thread_detail::internal_clock_t::now() + d); + d = (std::min)(d, CD(chrono::milliseconds(100))); + sleep_until(detail::internal_chrono_clock::now() + d); d = t - Clock::now(); } } @@ -93,9 +87,8 @@ namespace boost #ifdef BOOST_THREAD_USES_CHRONO template - void sleep_until(const chrono::time_point& t) + void sleep_until(const chrono::time_point& t) { - using namespace chrono; mutex mut; condition_variable cv; unique_lock lk(mut); @@ -105,13 +98,12 @@ namespace boost template void sleep_until(const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); while (d > CD::zero()) { - d = (std::min)(d, CD(milliseconds(100))); - sleep_until(thread_detail::internal_clock_t::now() + d); + d = (std::min)(d, CD(chrono::milliseconds(100))); + sleep_until(detail::internal_chrono_clock::now() + d); d = t - Clock::now(); } } @@ -119,10 +111,9 @@ namespace boost template void sleep_for(const chrono::duration& d) { - using namespace chrono; - if (d > duration::zero()) + if (d > chrono::duration::zero()) { - sleep_until(steady_clock::now() + d); + sleep_until(chrono::steady_clock::now() + d); } } diff --git a/include/boost/thread/win32/condition_variable.hpp b/include/boost/thread/win32/condition_variable.hpp index 185f78cd..d070a152 100644 --- a/include/boost/thread/win32/condition_variable.hpp +++ b/include/boost/thread/win32/condition_variable.hpp @@ -18,8 +18,7 @@ #include #include #include -#include -#include +#include #include #include @@ -417,7 +416,7 @@ namespace boost cv_status wait_until( unique_lock& lock, - const chrono::time_point& t) + const chrono::time_point& t) { const detail::internal_timespec_timepoint& ts = t; if (do_wait_until(lock, ts)) return cv_status::no_timeout; @@ -430,16 +429,14 @@ namespace boost unique_lock& lock, const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return cv_status::timeout; - d = (std::min)(d, CD(milliseconds(100))); - while (cv_status::timeout == wait_until(lock, thread_detail::internal_clock_t::now() + d)) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while (cv_status::timeout == wait_until(lock, detail::internal_chrono_clock::now() + d)) { d = t - Clock::now(); if ( d <= CD::zero() ) return cv_status::timeout; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return cv_status::no_timeout; } @@ -590,7 +587,7 @@ namespace boost cv_status wait_until( lock_type& lock, - const chrono::time_point& t) + const chrono::time_point& t) { const detail::internal_timespec_timepoint& ts = t; if (do_wait_until(lock, ts)) return cv_status::no_timeout; @@ -603,16 +600,14 @@ namespace boost lock_type& lock, const chrono::time_point& t) { - using namespace chrono; typedef typename common_type::type CD; CD d = t - Clock::now(); - if ( d <= CD::zero() ) return cv_status::timeout; - d = (std::min)(d, CD(milliseconds(100))); - while (cv_status::timeout == wait_until(lock, thread_detail::internal_clock_t::now() + d)) + d = (std::min)(d, CD(chrono::milliseconds(100))); + while (cv_status::timeout == wait_until(lock, detail::internal_chrono_clock::now() + d)) { d = t - Clock::now(); if ( d <= CD::zero() ) return cv_status::timeout; - d = (std::min)(d, CD(milliseconds(100))); + d = (std::min)(d, CD(chrono::milliseconds(100))); } return cv_status::no_timeout; } diff --git a/include/boost/thread/win32/thread_data.hpp b/include/boost/thread/win32/thread_data.hpp index 70a3a9c5..ecd31532 100644 --- a/include/boost/thread/win32/thread_data.hpp +++ b/include/boost/thread/win32/thread_data.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include diff --git a/src/pthread/thread.cpp b/src/pthread/thread.cpp index 3f6b1dbd..9ae10994 100644 --- a/src/pthread/thread.cpp +++ b/src/pthread/thread.cpp @@ -439,14 +439,15 @@ 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(); # if defined(BOOST_HAS_PTHREAD_DELAY_NP) # if defined(__IBMCPP__) || defined(_AIX) - BOOST_VERIFY(!pthread_delay_np(const_cast(&ts.get()))); + BOOST_VERIFY(!pthread_delay_np(const_cast(&ts2))); # else - BOOST_VERIFY(!pthread_delay_np(&ts.get())); + BOOST_VERIFY(!pthread_delay_np(&ts2)); # endif # elif defined(BOOST_HAS_NANOSLEEP) - nanosleep(&ts.get(), 0); + 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; diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_until_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_until_pass.cpp index 500b8e4e..f1e54cf4 100644 --- a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_until_pass.cpp +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_shared_lock_until_pass.cpp @@ -32,7 +32,6 @@ boost::shared_mutex m; int main() { -#if defined(BOOST_THREAD_PLATFORM_PTHREAD) { boost::shared_lock lk0(m); boost::unique_lock lk( boost::move(lk0), boost::chrono::steady_clock::now()+boost::chrono::milliseconds(1)); @@ -64,7 +63,6 @@ int main() BOOST_TEST(lk0.mutex() == 0); BOOST_TEST(lk0.owns_lock() == false); } -#endif return boost::report_errors(); } diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_for_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_for_pass.cpp index 7809bb59..7437ee0e 100644 --- a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_for_pass.cpp +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_for_pass.cpp @@ -30,7 +30,6 @@ boost::upgrade_mutex m; int main() { -#if defined(BOOST_THREAD_PLATFORM_PTHREAD) { boost::upgrade_lock lk0(m); boost::unique_lock lk(boost::move(lk0), boost::chrono::milliseconds(1)); @@ -62,7 +61,7 @@ int main() BOOST_TEST(lk0.mutex() == 0); BOOST_TEST(lk0.owns_lock() == false); } -#endif + return boost::report_errors(); } diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_try_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_try_pass.cpp index 1bab0cb0..fdbdf216 100644 --- a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_try_pass.cpp +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_try_pass.cpp @@ -28,7 +28,6 @@ boost::upgrade_mutex m; int main() { -#if defined(BOOST_THREAD_PLATFORM_PTHREAD) { boost::upgrade_lock lk0(m); boost::unique_lock lk(boost::move(lk0), boost::try_to_lock ); @@ -59,7 +58,7 @@ int main() BOOST_TEST(lk0.mutex() == 0); BOOST_TEST(lk0.owns_lock() == false); } -#endif + return boost::report_errors(); } diff --git a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_until_pass.cpp b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_until_pass.cpp index 744e3a2f..cd33f709 100644 --- a/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_until_pass.cpp +++ b/test/sync/mutual_exclusion/locks/unique_lock/cons/move_ctor_upgrade_lock_until_pass.cpp @@ -30,7 +30,6 @@ boost::upgrade_mutex m; int main() { -#if defined(BOOST_THREAD_PLATFORM_PTHREAD) { boost::upgrade_lock lk0(m); boost::unique_lock lk( boost::move(lk0), boost::chrono::steady_clock::now()+boost::chrono::milliseconds(1)); @@ -62,7 +61,7 @@ int main() BOOST_TEST(lk0.mutex() == 0); BOOST_TEST(lk0.owns_lock() == false); } -#endif + return boost::report_errors(); }