git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/9] wrapper: add sleep_nanosec

From
Siddh Raman Pant <siddh.raman.pant@oracle.com>
Date
May 19, 2026, 16:30 UTC
Message-ID
<6a8c2093643a385641ef0b2cde33839dc98d8678.1779207350.git.siddh.raman.pant@oracle.com>
In-Reply-To
<cover.1779207350.git.siddh.raman.pant@oracle.com>
Signed-off-by: Siddh Raman Pant <siddh.raman.pant@oracle.com>
---
 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 {
 	/*
-- 
2.53.0
Previous: Siddh Raman PantNext: Junio C Hamano
Message 25 of 29 in “Add support for an external command for fetching notes”
  1. 0/9 Add support for an external command for fetching notesSiddh Raman Pant, May 19, 2026
  2. 1/9 Documentation/git-range-diff: add missing notes options in synopsisSiddh Raman Pant, May 19, 2026
  3. Junio C HamanoMay 19, 2026
  4. Siddh Raman PantMay 20, 2026
  5. Junio C HamanoMay 21, 2026
  6. Siddh Raman PantMay 21, 2026
  7. 4/9 run-command: add support for timeout in command finisherSiddh Raman Pant, May 19, 2026
  8. Johannes SixtMay 21, 2026
  9. Oswald BuddenhagenMay 21, 2026
  10. Siddh Raman PantMay 21, 2026
  11. Johannes SixtMay 21, 2026
  12. Junio C HamanoMay 22, 2026
  13. Siddh Raman PantMay 22, 2026
  14. Jeff KingMay 22, 2026
  15. Siddh Raman PantMay 22, 2026
  16. 5/9 wrapper: add support for timeout and deadline in read helpersSiddh Raman Pant, May 19, 2026
  17. 6/9 t3301: cover generic displayed notes behaviorSiddh Raman Pant, May 19, 2026
  18. 7/9 notes: support an external command to display notesSiddh Raman Pant, May 19, 2026
  19. Junio C HamanoMay 20, 2026
  20. Siddh Raman PantMay 20, 2026
  21. brian m. carlsonMay 21, 2026
  22. Siddh Raman PantMay 21, 2026
  23. brian m. carlsonMay 21, 2026
  24. 2/9 notes: convert raw arg in format_display_notes() to boolSiddh Raman Pant, May 19, 2026
  25. 3/9 wrapper: add sleep_nanosecSiddh Raman Pant, May 19, 2026
  26. Junio C HamanoMay 19, 2026
  27. Siddh Raman PantMay 20, 2026
  28. 8/9 Documentation: document external notes command optionsSiddh Raman Pant, May 19, 2026
  29. 9/9 t: add tests for external notes commandSiddh Raman Pant, May 19, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.