2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * Various little time functions...
7 #include "wvtimeutils.h"
14 time_t msecdiff(const WvTime
&a
, const WvTime
&b
)
16 long long secdiff
= a
.tv_sec
- b
.tv_sec
;
17 long long usecdiff
= a
.tv_usec
- b
.tv_usec
;
18 long long msecs
= secdiff
* 1000 + usecdiff
/ 1000;
23 else if (msecs
< INT_MIN
)
39 WvTime
msecadd(const WvTime
&a
, time_t msec
)
42 b
.tv_sec
= a
.tv_sec
+ msec
/ 1000;
43 b
.tv_usec
= a
.tv_usec
+ (msec
% 1000) * 1000;
49 WvTime
tvdiff(const WvTime
&a
, const WvTime
&b
)
52 c
.tv_sec
= a
.tv_sec
- b
.tv_sec
;
53 c
.tv_usec
= a
.tv_usec
;
55 if (b
.tv_usec
> a
.tv_usec
)
61 c
.tv_usec
-= b
.tv_usec
;
68 static WvTime wvstime_cur
= wvtime();
71 const WvTime
&wvstime()
77 static void do_wvstime_sync(bool forward_only
)
81 wvstime_cur
= wvtime();
85 WvTime now
= wvtime();
86 if (wvstime_cur
< now
)
94 do_wvstime_sync(false);
98 void wvstime_sync_forward()
100 do_wvstime_sync(true);
104 void wvstime_set(const WvTime
&_new_time
)
106 wvstime_cur
= _new_time
;
110 void wvdelay(int msec_delay
)
115 usleep(msec_delay
* 1000);