mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
BUG/MINOR: time: make sure only one thread sets global_now at boot
All threads call tv_update_date(-1) at boot to set their own local time offset. While doing so they also overwrite global_now, which is not that much of a problem except that it's not done using an atomic write and that it will be overwritten by every there in parallel. We only need the first thread to set it anyway, so let's simply set it if not set and do it using a CAS. This should fix GH issue #111. This may be backported to 1.9.
This commit is contained in:
parent
237f8aef41
commit
43091ed161
@ -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() */
|
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 */
|
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> ms to <from>, set the result to <tv> and returns a pointer <tv>
|
* adds <ms> ms to <from>, set the result to <tv> and returns a pointer <tv>
|
||||||
@ -186,8 +186,11 @@ REGPRM2 void tv_update_date(int max_wait, int interrupted)
|
|||||||
after_poll = date;
|
after_poll = date;
|
||||||
samp_time = idle_time = 0;
|
samp_time = idle_time = 0;
|
||||||
ti->idle_pct = 100;
|
ti->idle_pct = 100;
|
||||||
global_now = (((unsigned long long)adjusted.tv_sec) << 32) +
|
old_now = global_now;
|
||||||
(unsigned int)adjusted.tv_usec;
|
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;
|
goto to_ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user