git: df1b0f580d3d - main - time: switch to fences for siginfo_recvd
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 21 Apr 2025 03:19:27 UTC
The branch main has been updated by kevans:
URL: https://cgit.FreeBSD.org/src/commit/?id=df1b0f580d3dc4dd165d84fbcc14d0eebd8ee2c4
commit df1b0f580d3dc4dd165d84fbcc14d0eebd8ee2c4
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-04-21 03:19:17 +0000
Commit: Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2025-04-21 03:19:17 +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)
Differential Revision: https://reviews.freebsd.org/D45574
---
usr.bin/time/time.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c
index 4c1ce06543e3..5478b23d52ec 100644
--- a/usr.bin/time/time.c
+++ b/usr.bin/time/time.c
@@ -40,6 +40,8 @@
#include <errno.h>
#include <locale.h>
#include <signal.h>
+#include <stdatomic.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -54,7 +56,7 @@ static void showtime(FILE *, struct timespec *, struct timespec *,
static void siginfo(int);
static void usage(void) __dead2;
-static volatile sig_atomic_t siginfo_recvd;
+static sig_atomic_t siginfo_recvd;
static char decimal_point;
static struct timespec before_ts;
static int hflag, pflag;
@@ -125,7 +127,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");
@@ -296,4 +301,5 @@ siginfo(int sig __unused)
{
siginfo_recvd = 1;
+ atomic_signal_fence(memory_order_release);
}