diff --git a/src/time.c b/src/time.c index 187f05142..e830f851a 100644 --- a/src/time.c +++ b/src/time.c @@ -30,7 +30,7 @@ THREAD_LOCAL struct timeval before_poll; /* system date before calling poll( THREAD_LOCAL struct timeval after_poll; /* system date after leaving poll() */ static THREAD_LOCAL struct timeval tv_offset; /* per-thread time ofsset relative to global time */ -volatile unsigned long long global_now; /* common date between all threads (32:32) */ +static volatile unsigned long long global_now; /* common date between all threads (32:32) */ /* * adds ms to , set the result to and returns a pointer @@ -186,8 +186,11 @@ REGPRM2 void tv_update_date(int max_wait, int interrupted) after_poll = date; samp_time = idle_time = 0; ti->idle_pct = 100; - global_now = (((unsigned long long)adjusted.tv_sec) << 32) + - (unsigned int)adjusted.tv_usec; + old_now = global_now; + if (!old_now) { // never set + new_now = (((unsigned long long)adjusted.tv_sec) << 32) + (unsigned int)adjusted.tv_usec; + _HA_ATOMIC_CAS(&global_now, &old_now, new_now); + } goto to_ms; }