From: Junio C Hamano <gitster@pobox.com>
To: Siddh Raman Pant <siddh.raman.pant@oracle.com>
Cc: git@vger.kernel.org, Calvin Wan <calvinwan@google.com>,
Patrick Steinhardt <ps@pks.im>,
Elijah Newren <newren@gmail.com>,
Kristoffer Haugsbakk <code@khaugsbakk.name>
Subject: Re: [PATCH 3/9] wrapper: add sleep_nanosec
Date: Wed, 20 May 2026 08:50:44 +0900 [thread overview]
Message-ID: <87qzn7q7qj.fsf@gitster.g> (raw)
In-Reply-To: <6a8c2093643a385641ef0b2cde33839dc98d8678.1779207350.git.siddh.raman.pant@oracle.com> (Siddh Raman Pant's message of "Tue, 19 May 2026 22:00:32 +0530")
Siddh Raman Pant <siddh.raman.pant@oracle.com> writes:
> Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
> ---
The space above the signed-off-by line should be utilized to explain
why we want this change. For the purpose of this series, why do we
want to sleep at nanosecond precision?
> wrapper.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
> wrapper.h | 1 +
> 2 files changed, 50 insertions(+)
>
> diff --git a/wrapper.c b/wrapper.c
> index 16f5a63fbb61..1349255f1eb4 100644
> --- a/wrapper.c
> +++ b/wrapper.c
> @@ -10,6 +10,7 @@
> #include "gettext.h"
> #include "strbuf.h"
> #include "trace2.h"
> +#include <time.h>
>
> #ifdef HAVE_RTLGENRANDOM
> /* This is required to get access to RtlGenRandom. */
> @@ -708,6 +709,54 @@ void sleep_millisec(int millisec)
> poll(NULL, 0, millisec);
> }
>
> +#ifdef GIT_WINDOWS_NATIVE
> +/* No nanosleep() on Windows, so fall-back to using sleep_millisec(). */
> +int sleep_nanosec(uint64_t nanosec)
> +{
> + uint64_t ns_in_1ms = 1000000ULL; /* 1 ms = 10^6 ns */
> +
> + uint64_t millisec = nanosec / ns_in_1ms;
> + if (nanosec % ns_in_1ms)
> + millisec++;
> +
> + /* Chunked sleep if we can't represent in integer. */
> + while (millisec > INT_MAX) {
> + sleep_millisec(INT_MAX);
> + millisec -= INT_MAX;
> + }
> +
> + sleep_millisec((int)millisec);
> +
> + return 0;
> +}
> +#else
> +/* Not Windows, so use the more exact nanosleep(). */
> +int sleep_nanosec(uint64_t nanosec)
> +{
> + int ret;
> + struct timespec duration, remaining;
> +
> + /* Construct the duration by dividing the given total (1s = 10^9ns). */
> + duration.tv_sec = nanosec / 1000000000ULL;
> + duration.tv_nsec = nanosec % 1000000000ULL;
> +
> + while(1) {
> + ret = nanosleep(&duration, &remaining);
> +
> + /* Continue sleeping if interrupted. */
> + if (ret == -1 && errno == EINTR) {
> + duration = remaining;
> + continue;
> + }
> +
> + /* Either success or an error. */
> + break;
> + }
> +
> + return ret;
> +}
> +#endif /* GIT_WINDOWS_NATIVE */
> +
> int xgethostname(char *buf, size_t len)
> {
> /*
> diff --git a/wrapper.h b/wrapper.h
> index 15ac3bab6e97..c39992893a81 100644
> --- a/wrapper.h
> +++ b/wrapper.h
> @@ -130,6 +130,7 @@ int warn_on_fopen_errors(const char *path);
> int open_nofollow(const char *path, int flags);
>
> void sleep_millisec(int millisec);
> +int sleep_nanosec(uint64_t nanosec);
>
> enum {
> /*
next prev parent reply other threads:[~2026-05-19 23:50 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 16:30 [PATCH 0/9] Add support for an external command for fetching notes Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 1/9] Documentation/git-range-diff: add missing notes options in synopsis Siddh Raman Pant
2026-05-19 23:47 ` Junio C Hamano
2026-05-20 7:00 ` Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 2/9] notes: convert raw arg in format_display_notes() to bool Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 3/9] wrapper: add sleep_nanosec Siddh Raman Pant
2026-05-19 23:50 ` Junio C Hamano [this message]
2026-05-20 7:07 ` Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 4/9] run-command: add support for timeout in command finisher Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 5/9] wrapper: add support for timeout and deadline in read helpers Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 6/9] t3301: cover generic displayed notes behavior Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 7/9] notes: support an external command to display notes Siddh Raman Pant
2026-05-20 0:03 ` Junio C Hamano
2026-05-20 6:59 ` Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 8/9] Documentation: document external notes command options Siddh Raman Pant
2026-05-19 16:30 ` [PATCH 9/9] t: add tests for external notes command Siddh Raman Pant
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=87qzn7q7qj.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=calvinwan@google.com \
--cc=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
--cc=newren@gmail.com \
--cc=ps@pks.im \
--cc=siddh.raman.pant@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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