summaryrefslogtreecommitdiff
path: root/lib/util/time.c
diff options
context:
space:
mode:
authorBjörn Jacke <bj@sernet.de>2010-09-06 20:27:24 +0200
committerBjörn Jacke <bj@sernet.de>2010-09-07 20:29:13 +0200
commitb428952eefd250d6d4ce77ad89325e9803940d11 (patch)
treeb831b1535c3e451042a8d4e8fbf5a8f8509dea09 /lib/util/time.c
parente64e3985688e57a882e0e128b256ec5f84c6f67a (diff)
downloadsamba-b428952eefd250d6d4ce77ad89325e9803940d11.tar.gz
samba-b428952eefd250d6d4ce77ad89325e9803940d11.tar.bz2
samba-b428952eefd250d6d4ce77ad89325e9803940d11.zip
lib/util: add time_mono() for monotonic time a la time()
Diffstat (limited to 'lib/util/time.c')
-rw-r--r--lib/util/time.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/util/time.c b/lib/util/time.c
index 5ecf93cb77..ed3b4f8e30 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -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