]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: clock: always use atomic ops for global_now_ms
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 19 Feb 2025 10:42:04 +0000 (11:42 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 21 Feb 2025 10:22:35 +0000 (11:22 +0100)
global_now_ms is shared between threads so we must give hint to the
compiler that read/writes operations should be performed atomically.

Everywhere global_now_ms was used, atomic ops were used, except in
clock_update_global_date() where a read was performed without using
atomic op. In practise it is not an issue because on most systems
such reads should be atomic already, but to prevent any confusion or
potential bug on exotic systems, let's use an explicit _HA_ATOMIC_LOAD
there.

This may be backported up to 2.8

src/clock.c

index 1a6a80be008886eec0e1559157f9b9673cd68130..5a264146d55ca1b5c33a5ef8a34a4fe02f9e3bfe 100644 (file)
@@ -270,7 +270,7 @@ void clock_update_global_date()
         * otherwise catch up.
         */
        old_now_ns = _HA_ATOMIC_LOAD(&global_now_ns);
-       old_now_ms = global_now_ms;
+       old_now_ms = _HA_ATOMIC_LOAD(&global_now_ms);
 
        do {
                if (now_ns < old_now_ns)