8 /** Time Specification.
10 * Use the inline RTTimeSpecGet/Set to operate on structure this so we
11 * can easily change the representation if required later.
13 * The current representation is in nanoseconds relative to the unix epoch
14 * (1970-01-01 00:00:00 UTC). This gives us an approximate span from
15 * 1678 to 2262 without sacrifying the resolution offered by the various
16 * host OSes (BSD & LINUX 1ns, NT 100ns).
18 typedef struct RTTIMESPEC
20 /** Nanoseconds since epoch.
21 * The name is intentially too long to be comfortable to use because you should be
22 * using inline helpers! */
23 int64_t i64NanosecondsRelativeToUnixEpoch
;
25 /** Pointer to a time spec structure. */
26 typedef RTTIMESPEC
*PRTTIMESPEC
;
27 /** Pointer to a const time spec structure. */
28 typedef const RTTIMESPEC
*PCRTTIMESPEC
;
32 * Gets the time as microseconds relative to the unix epoch.
34 * @returns microseconds relative to unix epoch.
35 * @param pTime The time spec to interpret.
37 DECLINLINE(int64_t) RTTimeSpecGetMicro(PCRTTIMESPEC pTime
)
39 return pTime
->i64NanosecondsRelativeToUnixEpoch
/ 1000;
43 * Gets the time as POSIX timeval.
46 * @param pTime The time spec to interpret.
47 * @param pTimeval Where to store the time as POSIX timeval.
49 DECLINLINE(struct timeval
*) RTTimeSpecGetTimeval(PCRTTIMESPEC pTime
, struct timeval
*pTimeval
)
51 int64_t i64
= RTTimeSpecGetMicro(pTime
);
52 int32_t i32Micro
= (int32_t)(i64
% 1000000);
59 pTimeval
->tv_sec
= (time_t)i64
;
60 pTimeval
->tv_usec
= i32Micro
;
65 * Sets the time given by seconds relative to the unix epoch.
68 * @param pTime The time spec to modify.
69 * @param i64Seconds The new time in seconds.
71 DECLINLINE(PRTTIMESPEC
) RTTimeSpecSetSeconds(PRTTIMESPEC pTime
, int64_t i64Seconds
)
73 pTime
->i64NanosecondsRelativeToUnixEpoch
= i64Seconds
* 1000000000;