[sysprof] clock: handle uninitialized clock gracefully



commit 6da2a3be4ba93d18d97e932a3d8beb37af8c80e9
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 16 12:30:10 2018 +0100

    clock: handle uninitialized clock gracefully
    
    If we haven't discovered the proper clock, just default to monotonic.

 lib/sp-clock.h |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/lib/sp-clock.h b/lib/sp-clock.h
index 0b604fc..7b2f3fe 100644
--- a/lib/sp-clock.h
+++ b/lib/sp-clock.h
@@ -34,8 +34,11 @@ static inline SpTimeStamp
 sp_clock_get_current_time (void)
 {
   struct timespec ts;
+  SpClock clock = sp_clock;
 
-  clock_gettime (sp_clock, &ts);
+  if G_UNLIKELY (clock == -1)
+    clock = CLOCK_MONOTONIC;
+  clock_gettime (clock, &ts);
 
   return (ts.tv_sec * G_GINT64_CONSTANT (1000000000)) + ts.tv_nsec;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]