1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

lib/util: add time_mono() for monotonic time a la time()

This commit is contained in:
Björn Jacke 2010-09-06 20:27:24 +02:00
parent e64e398568
commit b428952eef
2 changed files with 26 additions and 0 deletions

View File

@ -65,6 +65,27 @@ _PUBLIC_ void clock_gettime_mono(struct timespec *tp)
}
}
/**
a wrapper to preferably get the monotonic time in seconds
as this is only second resolution we can use the cached
(and much faster) COARS clock variant
**/
_PUBLIC_ time_t time_mono(time_t *t)
{
struct timespec tp;
int rc = -1;
#ifdef CLOCK_MONOTONIC_COARSE
rc = clock_gettime(CLOCK_MONOTONIC_COARSE,&tp);
#endif
if (rc != 0) {
clock_gettime_mono(&tp);
}
if (t != NULL) {
*t = tp.tv_sec;
}
return tp.tv_sec;
}
#define TIME_FIXUP_CONSTANT 11644473600LL

View File

@ -55,6 +55,11 @@ a wrapper to preferably get the monotonic time
**/
_PUBLIC_ void clock_gettime_mono(struct timespec *tp);
/**
a wrapper to preferably get the monotonic time in s
**/
_PUBLIC_ time_t time_mono(time_t *t);
/**
interpret an 8 byte "filetime" structure to a time_t
It's originally in "100ns units since jan 1st 1601"