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)
This commit is contained in:
Kyle Evans 2025-04-20 22:19:17 -05:00
parent 73f88915a1
commit 8b42f57eeb

View file

@ -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);
}