summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-05-27 13:46:05 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-05-27 14:04:39 -0400
commit4704703d0404e0d91edc6a2a52d99b21b03770dc (patch)
treefb79ea7a06e56ff28e40815f82134eec54c65460 /src
parent06b9a89a09237e38115f871179ab2e50f34e3e77 (diff)
downloadbfs-4704703d0404e0d91edc6a2a52d99b21b03770dc.tar.xz
eval: Use a flag instead of a counter for SIGINFO
Diffstat (limited to 'src')
-rw-r--r--src/eval.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/eval.c b/src/eval.c
index 36b2f11..c28b9ec 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1378,8 +1378,8 @@ struct callback_args {
struct timespec last_status;
/** SIGINFO hook. */
struct sighook *info_hook;
- /** Number of times SIGINFO was caught (even: hide; odd: show). */
- atomic size_t info_count;
+ /** Flag set by SIGINFO hook. */
+ atomic bool info_flag;
#ifdef NOKERNINFO
/** atsigexit() hook. */
@@ -1415,17 +1415,16 @@ static enum bftw_action eval_callback(const struct BFTW *ftwbuf, void *ptr) {
state.quit = false;
// Check whether SIGINFO was delivered and show/hide the bar
- bool status = load(&args->info_count, relaxed) % 2;
- if (status && !args->bar) {
- args->bar = bfs_bar_show();
- if (!args->bar) {
- // Don't keep trying
- fetch_sub(&args->info_count, 1, relaxed);
- bfs_warning(ctx, "Couldn't show status bar: %s.\n", errstr());
+ if (exchange(&args->info_flag, false, relaxed)) {
+ if (args->bar) {
+ bfs_bar_hide(args->bar);
+ args->bar = NULL;
+ } else {
+ args->bar = bfs_bar_show();
+ if (!args->bar) {
+ bfs_warning(ctx, "Couldn't show status bar: %s.\n", errstr());
+ }
}
- } else if (!status && args->bar) {
- bfs_bar_hide(args->bar);
- args->bar = NULL;
}
if (args->bar) {
@@ -1504,7 +1503,7 @@ done:
/** Show/hide the bar in response to SIGINFO. */
static void eval_siginfo(int sig, siginfo_t *info, void *ptr) {
struct callback_args *args = ptr;
- fetch_add(&args->info_count, 1, relaxed);
+ store(&args->info_flag, true, relaxed);
}
#ifdef NOKERNINFO
@@ -1749,9 +1748,7 @@ int bfs_eval(struct bfs_ctx *ctx) {
if (ctx->status) {
args.bar = bfs_bar_show();
- if (args.bar) {
- atomic_init(&args.info_count, 1);
- } else {
+ if (!args.bar) {
bfs_warning(ctx, "Couldn't show status bar: %s.\n\n", errstr());
}
}