From: "Carlo Marcelo Arenas Belón via GitGitGadget" <gitgitgadget@gmail•com>
To: git@vger•kernel.org
Cc: "Nicolas Pitre" <nico@fluxnic•net>,
"Johannes Sixt" <j6t@kdbg•org>,
"Carlo Marcelo Arenas Belón" <carenas@gmail•com>,
"Carlo Marcelo Arenas Belón" <carenas@gmail•com>
Subject: [PATCH 2/2] progress: add a shutting down state to the SIGALRM handler
Date: Sat, 23 Aug 2025 13:22:57 +0000 [thread overview]
Message-ID: <0db98c3478e5e2f1aadcf6d773cf6519af482630.1755955378.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1960.git.1755955377.gitgitgadget@gmail.com>
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <carenas@gmail•com>
In a previous commit, sigitimer() was replaced by alarm(), but to
keep the timer active, an extra call to `alarm(1)` was added to
the signal handler, opening a potential race condition whem the
timer is being cleared.
To avoid that, add an extra state to set during shutdown and
adjust the logic to flag the potential need to update progress
into the first bit instead.
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail•com>
---
progress.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/progress.c b/progress.c
index 71b305d1625d..49e58e094a3f 100644
--- a/progress.c
+++ b/progress.c
@@ -50,6 +50,11 @@ struct progress {
int split;
};
+/*
+ * 0: no progress to report
+ * 1: potential update for progress to report
+ * 2: no more progress to report
+ */
static volatile sig_atomic_t progress_update;
/*
@@ -66,8 +71,10 @@ void progress_test_force_update(void)
static void progress_interval(int signum UNUSED)
{
- progress_update = 1;
- alarm(1);
+ if (progress_update != 2) {
+ alarm(1);
+ progress_update = 1;
+ }
}
static void set_progress_signal(void)
@@ -93,6 +100,7 @@ static void clear_progress_signal(void)
if (progress_testing)
return;
+ progress_update = 2;
alarm(0);
signal(SIGALRM, SIG_IGN);
progress_update = 0;
@@ -111,14 +119,14 @@ static void display(struct progress *progress, uint64_t n, const char *done)
int show_update = 0;
int last_count_len = counters_sb->len;
- if (progress->delay && (!progress_update || --progress->delay))
+ if (progress->delay && (!(progress_update & 1) || --progress->delay))
return;
progress->last_value = n;
tp = (progress->throughput) ? progress->throughput->display.buf : "";
if (progress->total) {
unsigned percent = n * 100 / progress->total;
- if (percent != progress->last_percent || progress_update) {
+ if (percent != progress->last_percent || (progress_update & 1)) {
progress->last_percent = percent;
strbuf_reset(counters_sb);
@@ -128,7 +136,7 @@ static void display(struct progress *progress, uint64_t n, const char *done)
tp);
show_update = 1;
}
- } else if (progress_update) {
+ } else if (progress_update & 1) {
strbuf_reset(counters_sb);
strbuf_addf(counters_sb, "%"PRIuMAX"%s", (uintmax_t)n, tp);
show_update = 1;
@@ -239,7 +247,7 @@ void display_throughput(struct progress *progress, uint64_t total)
tp->idx = (tp->idx + 1) % TP_IDX_MAX;
throughput_string(&tp->display, total, rate);
- if (progress->last_value != -1 && progress_update)
+ if (progress->last_value != -1 && (progress_update & 1))
display(progress, progress->last_value, NULL);
}
--
gitgitgadget
next prev parent reply other threads:[~2025-08-23 13:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-23 13:22 [PATCH 0/2] progress: replace setitimer() with alarm() Carlo Marcelo Arenas Belón via GitGitGadget
2025-08-23 13:22 ` [PATCH 1/2] " Carlo Marcelo Arenas Belón via GitGitGadget
2025-08-23 13:22 ` Carlo Marcelo Arenas Belón via GitGitGadget [this message]
2025-08-23 16:24 ` [PATCH 0/2] " Johannes Sixt
2025-08-23 19:38 ` Carlo Marcelo Arenas Belón
2025-08-23 19:55 ` Johannes Sixt
2025-08-23 21:33 ` Junio C Hamano
2025-08-23 21:47 ` Junio C Hamano
2025-08-23 22:03 ` Johannes Sixt
2025-08-24 15:31 ` [PATCH] progress: pay attention to (customized) delay time Johannes Sixt
2025-08-25 17:00 ` Junio C Hamano
2025-08-25 18:11 ` Carlo Marcelo Arenas Belón
2025-08-25 18:50 ` Junio C Hamano
2025-08-25 19:16 ` [PATCH v2] " Johannes Sixt
2025-08-25 22:52 ` Junio C Hamano
2025-08-24 16:11 ` [PATCH 0/2] progress: replace setitimer() with alarm() Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0db98c3478e5e2f1aadcf6d773cf6519af482630.1755955378.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail$(echo .)com \
--cc=carenas@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=j6t@kdbg$(echo .)org \
--cc=nico@fluxnic$(echo .)net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox