|
1 // Copyright (C) 2001-2003 |
|
2 // William E. Kempf |
|
3 // Copyright (C) 2007-8 Anthony Williams |
|
4 // |
|
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) |
|
7 |
|
8 #ifndef BOOST_XTIME_WEK070601_HPP |
|
9 #define BOOST_XTIME_WEK070601_HPP |
|
10 |
|
11 #include <boost/thread/detail/config.hpp> |
|
12 |
|
13 #include <boost/cstdint.hpp> |
|
14 #include <boost/thread/thread_time.hpp> |
|
15 #include <boost/date_time/posix_time/conversion.hpp> |
|
16 |
|
17 #include <boost/config/abi_prefix.hpp> |
|
18 |
|
19 namespace boost { |
|
20 |
|
21 enum xtime_clock_types |
|
22 { |
|
23 TIME_UTC=1 |
|
24 // TIME_TAI, |
|
25 // TIME_MONOTONIC, |
|
26 // TIME_PROCESS, |
|
27 // TIME_THREAD, |
|
28 // TIME_LOCAL, |
|
29 // TIME_SYNC, |
|
30 // TIME_RESOLUTION |
|
31 }; |
|
32 |
|
33 struct xtime |
|
34 { |
|
35 #if defined(BOOST_NO_INT64_T) |
|
36 typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX |
|
37 #else |
|
38 typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX |
|
39 #endif |
|
40 |
|
41 typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND |
|
42 |
|
43 xtime_sec_t sec; |
|
44 xtime_nsec_t nsec; |
|
45 |
|
46 operator system_time() const |
|
47 { |
|
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); |
|
52 #else |
|
53 boost::posix_time::microseconds((nsec+500)/1000); |
|
54 #endif |
|
55 } |
|
56 |
|
57 }; |
|
58 |
|
59 inline xtime get_xtime(boost::system_time const& abs_time) |
|
60 { |
|
61 xtime res; |
|
62 boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0); |
|
63 |
|
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())); |
|
66 return res; |
|
67 } |
|
68 |
|
69 inline int xtime_get(struct xtime* xtp, int clock_type) |
|
70 { |
|
71 if (clock_type == TIME_UTC) |
|
72 { |
|
73 *xtp=get_xtime(get_system_time()); |
|
74 return clock_type; |
|
75 } |
|
76 return 0; |
|
77 } |
|
78 |
|
79 |
|
80 inline int xtime_cmp(const xtime& xt1, const xtime& xt2) |
|
81 { |
|
82 if (xt1.sec == xt2.sec) |
|
83 return (int)(xt1.nsec - xt2.nsec); |
|
84 else |
|
85 return (xt1.sec > xt2.sec) ? 1 : -1; |
|
86 } |
|
87 |
|
88 } // namespace boost |
|
89 |
|
90 #include <boost/config/abi_suffix.hpp> |
|
91 |
|
92 #endif //BOOST_XTIME_WEK070601_HPP |