1 // Copyright (C) 2001-2003
3 // Copyright (C) 2007-8 Anthony Williams
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BOOST_XTIME_WEK070601_HPP
9 #define BOOST_XTIME_WEK070601_HPP
11 #include <boost/thread/detail/config.hpp>
12 #if defined BOOST_THREAD_USES_DATETIME
14 #include <boost/cstdint.hpp>
15 #include <boost/thread/thread_time.hpp>
16 #include <boost/date_time/posix_time/conversion.hpp>
18 #include <boost/config/abi_prefix.hpp>
22 enum xtime_clock_types
36 #if defined(BOOST_NO_INT64_T)
37 typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
39 typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
42 typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
47 operator system_time() const
49 return boost::posix_time::from_time_t(0)+
50 boost::posix_time::seconds(static_cast<long>(sec))+
51 #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
52 boost::posix_time::nanoseconds(nsec);
54 boost::posix_time::microseconds((nsec+500)/1000);
60 inline ::boost::xtime get_xtime(boost::system_time const& abs_time)
63 boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
65 res.sec=static_cast< ::boost::xtime::xtime_sec_t>(time_since_epoch.total_seconds());
66 res.nsec=static_cast< ::boost::xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
70 inline int xtime_get(struct ::boost::xtime* xtp, int clock_type)
72 if (clock_type == TIME_UTC_)
74 *xtp=get_xtime(get_system_time());
81 inline int xtime_cmp(const ::boost::xtime& xt1, const ::boost::xtime& xt2)
83 if (xt1.sec == xt2.sec)
84 return (int)(xt1.nsec - xt2.nsec);
86 return (xt1.sec > xt2.sec) ? 1 : -1;
91 #include <boost/config/abi_suffix.hpp>
93 #endif //BOOST_XTIME_WEK070601_HPP