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>
13 #include <boost/cstdint.hpp>
14 #include <boost/thread/thread_time.hpp>
15 #include <boost/date_time/posix_time/conversion.hpp>
17 #include <boost/config/abi_prefix.hpp>
21 enum xtime_clock_types
35 #if defined(BOOST_NO_INT64_T)
36 typedef int_fast32_t xtime_sec_t
; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
38 typedef int_fast64_t xtime_sec_t
; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
41 typedef int_fast32_t xtime_nsec_t
; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
46 operator system_time() const
48 return boost::posix_time::from_time_t(0)+
49 boost::posix_time::seconds(static_cast<long>(sec
))+
50 #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
51 boost::posix_time::nanoseconds(nsec
);
53 boost::posix_time::microseconds((nsec
+500)/1000);
59 inline xtime
get_xtime(boost::system_time
const& abs_time
)
62 boost::posix_time::time_duration
const time_since_epoch
=abs_time
-boost::posix_time::from_time_t(0);
64 res
.sec
=static_cast<xtime::xtime_sec_t
>(time_since_epoch
.total_seconds());
65 res
.nsec
=static_cast<xtime::xtime_nsec_t
>(time_since_epoch
.fractional_seconds()*(1000000000/time_since_epoch
.ticks_per_second()));
69 inline int xtime_get(struct xtime
* xtp
, int clock_type
)
71 if (clock_type
== TIME_UTC
)
73 *xtp
=get_xtime(get_system_time());
80 inline int xtime_cmp(const xtime
& xt1
, const xtime
& xt2
)
82 if (xt1
.sec
== xt2
.sec
)
83 return (int)(xt1
.nsec
- xt2
.nsec
);
85 return (xt1
.sec
> xt2
.sec
) ? 1 : -1;
90 #include <boost/config/abi_suffix.hpp>
92 #endif //BOOST_XTIME_WEK070601_HPP