clock: handle uninitialized clock gracefully

If we haven't discovered the proper clock, just default to monotonic.
This commit is contained in:
Christian Hergert
2018-05-16 12:30:10 +01:00
parent f8176b699b
commit 6da2a3be4b

View File

@ -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;
}