mirror of
https://git.freebsd.org/src.git
synced 2026-01-11 19:57:22 +00:00
time: switch to fences for siginfo_recvd
This effectively reverts
6e824f3713 ("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
This commit is contained in:
parent
d7441aa9b0
commit
df1b0f580d
1 changed files with 8 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue