git: 8b42f57eebde - stable/14 - time: switch to fences for siginfo_recvd
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 26 Apr 2025 03:21:21 UTC
The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=8b42f57eebde72d463986bdcfddf8ee8ecadc561 commit 8b42f57eebde72d463986bdcfddf8ee8ecadc561 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2025-04-21 03:19:17 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2025-04-26 03:19:49 +0000 time: switch to fences for siginfo_recvd This effectively reverts 6e824f3713011 ("time: siginfo_recvd needs to be marked volatile") because it was actually wrong. Switch to C11 signal fence, which provides a compiler barrier that will do the right thing. Reported by: kib Reviewed by: kib (slightly earlier version) (cherry picked from commit df1b0f580d3dc4dd165d84fbcc14d0eebd8ee2c4) --- usr.bin/time/time.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c index 8e45f1283317..f883db17a59e 100644 --- a/usr.bin/time/time.c +++ b/usr.bin/time/time.c @@ -52,6 +52,8 @@ static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93"; #include <errno.h> #include <locale.h> #include <signal.h> +#include <stdatomic.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -137,7 +139,10 @@ main(int argc, char **argv) (void)signal(SIGINFO, siginfo); (void)siginterrupt(SIGINFO, 1); while (wait4(pid, &status, 0, &ru) != pid) { - if (siginfo_recvd) { + bool do_siginfo = siginfo_recvd != 0; + + atomic_signal_fence(memory_order_acquire); + if (do_siginfo) { siginfo_recvd = 0; if (clock_gettime(CLOCK_MONOTONIC, &after)) err(1, "clock_gettime"); @@ -308,4 +313,5 @@ siginfo(int sig __unused) { siginfo_recvd = 1; + atomic_signal_fence(memory_order_release); }