1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
From: Pavel Sountsov <siege@google.com>
Date: Mon, 18 Jul 2022 21:10:17 -0700
Subject: Use CLOCK_REALTIME instead of CLOCK_MONOTONIC.
The former has spotty support across Unixes and in particular is not
used (by default) by pthread_cond_timedwait which caused #1349. While it
is possible to alter that default (thus fixing this bug a different
way), the function to do that (pthread_condattr_setclock) has even
spottier support (e.g. it is not exposed on my Ubuntu 20.04).
Fixes #1349
---
src/unix/utime.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/unix/utime.c b/src/unix/utime.c
index 2464767..d2b2811 100644
--- a/src/unix/utime.c
+++ b/src/unix/utime.c
@@ -38,7 +38,7 @@ struct timespec _al_unix_initial_time;
*/
void _al_unix_init_time(void)
{
- clock_gettime(CLOCK_MONOTONIC, &_al_unix_initial_time);
+ clock_gettime(CLOCK_REALTIME, &_al_unix_initial_time);
}
@@ -48,7 +48,7 @@ double _al_unix_get_time(void)
struct timespec now;
double time;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ clock_gettime(CLOCK_REALTIME, &now);
time = (double) (now.tv_sec - _al_unix_initial_time.tv_sec)
+ (double) (now.tv_nsec - _al_unix_initial_time.tv_nsec) * 1.0e-9;
return time;
@@ -79,7 +79,7 @@ void _al_unix_init_timeout(ALLEGRO_TIMEOUT *timeout, double seconds)
ASSERT(ut);
- clock_gettime(CLOCK_MONOTONIC, &now);
+ clock_gettime(CLOCK_REALTIME, &now);
if (seconds <= 0.0) {
ut->abstime.tv_sec = now.tv_sec;
|