Index: boost/thread/pthread/mutex.hpp =================================================================== --- boost/thread/pthread/mutex.hpp (revision 81015) +++ boost/thread/pthread/mutex.hpp (working copy) @@ -10,17 +10,11 @@ #include #include #include -#include -#include #include #include -#include #include -#ifdef BOOST_THREAD_USES_CHRONO -#include -#include -#endif #include +#include #ifdef _POSIX_TIMEOUTS #if _POSIX_TIMEOUTS >= 0 && _POSIX_C_SOURCE>=200112L @@ -146,16 +140,39 @@ #endif } - template - bool timed_lock(TimeDuration const & relative_time) + template< typename T > + bool timed_lock(T const& time) { - return timed_lock(get_system_time()+relative_time); + return timed_lock_dispatch(detail::thread_time_traits< T >::to_thread_unit(time)); } - bool timed_lock(boost::xtime const & absolute_time) + + template< typename DurationT > + bool try_lock_for(DurationT const& relative_time) { - return timed_lock(system_time(absolute_time)); + detail::thread_duration dur = detail::thread_time_traits< DurationT >::to_thread_unit(relative_time); + detail::thread_time absolute_time = detail::thread_time::now() + dur; + return do_try_lock_until(absolute_time.get()); } + template< typename TimeT > + bool try_lock_until(TimeT const& absolute_time) + { + return do_try_lock_until(detail::thread_time_traits< TimeT >::to_thread_unit(absolute_time).get()); + } + + private: + bool timed_lock_dispatch(detail::thread_duration const& relative_time) + { + detail::thread_time absolute_time = detail::thread_time::now() + relative_time; + return do_try_lock_until(absolute_time.get()); + } + bool timed_lock_dispatch(detail::thread_time const& absolute_time) + { + return do_try_lock_until(absolute_time.get()); + } + + public: + #ifdef BOOST_PTHREAD_HAS_TIMEDLOCK void lock() { @@ -182,8 +199,8 @@ BOOST_ASSERT(!res || res==ETIMEDOUT); return !res; } + public: - #else void lock() { @@ -232,45 +249,6 @@ public: #endif - bool timed_lock(system_time const & abs_time) - { - struct timespec const ts=detail::get_timespec(abs_time); - return do_try_lock_until(ts); - } - -#ifdef BOOST_THREAD_USES_CHRONO - template - bool try_lock_for(const chrono::duration& rel_time) - { - return try_lock_until(chrono::steady_clock::now() + rel_time); - } - template - bool try_lock_until(const chrono::time_point& t) - { - using namespace chrono; - system_clock::time_point s_now = system_clock::now(); - typename Clock::time_point c_now = Clock::now(); - return try_lock_until(s_now + ceil(t - c_now)); - } - template - bool try_lock_until(const chrono::time_point& t) - { - using namespace chrono; - typedef time_point nano_sys_tmpt; - return try_lock_until(nano_sys_tmpt(ceil(t.time_since_epoch()))); - } - bool try_lock_until(const chrono::time_point& tp) - { - using namespace chrono; - nanoseconds d = tp.time_since_epoch(); - timespec ts; - seconds s = duration_cast(d); - ts.tv_sec = static_cast(s.count()); - ts.tv_nsec = static_cast((d - s).count()); - return do_try_lock_until(ts); - } -#endif - #define BOOST_THREAD_DEFINES_TIMED_MUTEX_NATIVE_HANDLE typedef pthread_mutex_t* native_handle_type; native_handle_type native_handle() Index: boost/date_time/time_duration.hpp =================================================================== --- boost/date_time/time_duration.hpp (revision 81015) +++ boost/date_time/time_duration.hpp (working copy) @@ -15,6 +15,7 @@ #include #include #include +#include namespace boost { namespace date_time { @@ -42,6 +43,7 @@ * either (haven't tried) */ { public: + typedef void _is_boost_date_time_duration; typedef T duration_type; //the subclass typedef rep_type traits_type; typedef typename rep_type::day_type day_type; Index: boost/date_time/time.hpp =================================================================== --- boost/date_time/time.hpp (revision 81015) +++ boost/date_time/time.hpp (working copy) @@ -2,7 +2,7 @@ #define DATE_TIME_TIME_HPP___ /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc. - * Use, modification and distribution is subject to the + * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst @@ -17,29 +17,30 @@ #include #include #include +#include namespace boost { namespace date_time { //! Representation of a precise moment in time, including the date. - /*! + /*! This class is a skeleton for the interface of a temporal type - with a resolution that is higher than a day. It is intended that - this class be the base class and that the actual time - class be derived using the BN pattern. In this way, the derived - class can make decisions such as 'should there be a default constructor' + with a resolution that is higher than a day. It is intended that + this class be the base class and that the actual time + class be derived using the BN pattern. In this way, the derived + class can make decisions such as 'should there be a default constructor' and what should it set its value to, should there be optional constructors say allowing only an time_durations that generate a time from a clock,etc. So, in fact multiple time types can be created for a time_system with different construction policies, and all of them can perform basic - operations by only writing a copy constructor. Finally, compiler - errors are also shorter. - + operations by only writing a copy constructor. Finally, compiler + errors are also shorter. + The real behavior of the time class is provided by the time_system template parameter. This class must provide all the logic for addition, subtraction, as well as define all the interface types. - + */ template @@ -49,15 +50,16 @@ > > { public: + typedef void _is_boost_date_time_time_point; typedef T time_type; typedef typename time_system::time_rep_type time_rep_type; typedef typename time_system::date_type date_type; typedef typename time_system::date_duration_type date_duration_type; typedef typename time_system::time_duration_type time_duration_type; //typedef typename time_system::hms_type hms_type; - - base_time(const date_type& day, - const time_duration_type& td, + + base_time(const date_type& day, + const time_duration_type& td, dst_flags dst=not_dst) : time_(time_system::get_time_rep(day, td, dst)) {} @@ -75,15 +77,15 @@ { return time_system::get_time_of_day(time_); } - /*! Optional bool parameter will return time zone as an offset - * (ie "+07:00"). Empty string is returned for classes that do + /*! Optional bool parameter will return time zone as an offset + * (ie "+07:00"). Empty string is returned for classes that do * not use a time_zone */ std::string zone_name(bool /*as_offset*/=false) const { return time_system::zone_name(time_); } - /*! Optional bool parameter will return time zone as an offset - * (ie "+07:00"). Empty string is returned for classes that do + /*! Optional bool parameter will return time zone as an offset + * (ie "+07:00"). Empty string is returned for classes that do * not use a time_zone */ std::string zone_abbrev(bool /*as_offset*/=false) const { @@ -103,7 +105,7 @@ //! check to see if date is one of the infinity values bool is_infinity() const { - return (is_pos_infinity() || is_neg_infinity()); + return (is_pos_infinity() || is_neg_infinity()); } //! check to see if date is greater than all possible dates bool is_pos_infinity() const @@ -170,12 +172,12 @@ { return time_system::subtract_time_duration(time_, rhs); } - time_type operator-=(const time_duration_type& td) + time_type operator-=(const time_duration_type& td) { time_ = (time_system::get_time_rep(date(), time_of_day() - td)); return time_type(time_); } - + protected: time_rep_type time_; };