time: prefer CLOCK_BOOTTIME for clock_gettime_mono()
authorBjörn Jacke <bj@sernet.de>
Wed, 3 Jul 2013 16:57:57 +0000 (18:57 +0200)
committerSimo Sorce <idra@samba.org>
Fri, 5 Jul 2013 14:47:34 +0000 (16:47 +0200)
this clock moves on while the machine was suspended. This is what we prefer
actually.

Signed-off-by: Björn Jacke <bj@sernet.de>
Reviewed-by: Simo Sorce <idra@samba.org>
Autobuild-User(master): Simo Sorce <idra@samba.org>
Autobuild-Date(master): Fri Jul  5 16:47:34 CEST 2013 on sn-devel-104

lib/util/time.c

index bc8712085931f9a2f383863f074417706f342899..05251dd3b56cd65dae3ae2b62a01bf4affe8ff3c 100644 (file)
@@ -62,9 +62,19 @@ a wrapper to preferably get the monotonic time
 **/
 _PUBLIC_ void clock_gettime_mono(struct timespec *tp)
 {
-       if (clock_gettime(CUSTOM_CLOCK_MONOTONIC,tp) != 0) {
-               clock_gettime(CLOCK_REALTIME,tp);
+/* prefer a suspend aware monotonic CLOCK_BOOTTIME: */
+#ifdef CLOCK_BOOTTIME
+       if (clock_gettime(CLOCK_BOOTTIME,tp) == 0) {
+               return;
        }
+#endif
+/* then try the  monotonic clock: */
+#if CUSTOM_CLOCK_MONOTONIC != CLOCK_REALTIME
+       if (clock_gettime(CUSTOM_CLOCK_MONOTONIC,tp) == 0) {
+               return;
+       }
+#endif
+       clock_gettime(CLOCK_REALTIME,tp);
 }
 
 /**