21 #ifndef __SSRC_WISP_UTILITY_TIME_VALUE_H
22 #define __SSRC_WISP_UTILITY_TIME_VALUE_H
32 #if defined(WISP_HAVE_MACH_CLOCK_H)
33 #include <mach/mach_host.h>
34 #include <mach/clock.h>
39 #define __WISP_BILLION 1000000000
45 #ifdef WISP_HAVE_CLOCK_GETTIME
46 static int gettime(::clockid_t clk_id, timespec *tp) {
47 return ::clock_gettime(clk_id, tp);
49 #elif defined(WISP_HAVE_CLOCK_GET_TIME)
50 static int gettime(::clock_id_t clk_id, timespec *tp) {
51 ::clock_serv_t clock_serv;
52 ::mach_timespec_t mtp;
55 if((::host_get_clock_service(mach_host_self(), clk_id, &clock_serv) ==
58 if(::clock_get_time(clock_serv, &mtp) == KERN_SUCCESS) {
59 tp->tv_sec = mtp.tv_sec;
60 tp->tv_nsec = mtp.tv_nsec;
67 # error "System does not implement POSIX clock_gettime or MACH clock_get_time."
85 _time.tv_sec = _time.tv_nsec = 0;
90 SSRC_DECL_THROW(std::invalid_argument)
93 throw std::invalid_argument(
"negative time");
105 _time.tv_sec = millisec / 1000;
106 _time.tv_nsec = (millisec % 1000) * 1000000;
110 #ifdef WISP_HAVE_CLOCK_GETTIME
111 gettime(CLOCK_REALTIME, &_time);
112 #elif defined(WISP_HAVE_CLOCK_GET_TIME)
113 gettime(CALENDAR_CLOCK, &_time);
119 #ifdef WISP_HAVE_CLOCK_GETTIME
120 gettime(CLOCK_MONOTONIC, &_time);
121 #elif defined(WISP_HAVE_CLOCK_GET_TIME)
122 gettime(SYSTEM_CLOCK, &_time);
128 return (static_cast<ms_type>(_time.tv_sec)*1000 +
129 (_time.tv_nsec + 999999)/1000000);
137 return _time.tv_nsec;
141 _time.tv_sec+=t2._time.tv_sec;
142 _time.tv_nsec+=t2._time.tv_nsec;
153 _time.tv_sec-=t2._time.tv_sec;
154 _time.tv_nsec-=t2._time.tv_nsec;
156 if(_time.tv_nsec < 0) {
165 return (t1._time.tv_sec == t2._time.tv_sec &&
166 t1._time.tv_nsec == t2._time.tv_nsec);
170 return (t1._time.tv_sec < t2._time.tv_sec ||
171 (t1._time.tv_sec == t2._time.tv_sec &&
172 t1._time.tv_nsec < t2._time.tv_nsec));
175 template<
class Archive>
177 ar & _time.tv_sec & _time.tv_nsec;
192 TimeValue(TimeValue::sec_type_traits::max(), 0);
194 #undef __WISP_BILLION