[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210512114728.19015-1-broonie@kernel.org>
Date: Wed, 12 May 2021 12:47:28 +0100
From: Mark Brown <broonie@...nel.org>
To: Willy Tarreau <w@....eu>
Cc: linux-kernel@...r.kernel.org, Mark Brown <broonie@...nel.org>
Subject: [PATCH v2] tools/nolibc: Implement msleep()
Allow users to implement shorter delays than a full second by implementing
msleep().
Signed-off-by: Mark Brown <broonie@...nel.org>
---
v2:
- Support delays of more than a second.
- Return the number of seconds remaining if the delay does not
complete.
tools/include/nolibc/nolibc.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 8b7a9830dd22..01400d36ce99 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -2243,6 +2243,17 @@ unsigned int sleep(unsigned int seconds)
return 0;
}
+static __attribute__((unused))
+int msleep(unsigned int msecs)
+{
+ struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 };
+
+ if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
+ return my_timeval.tv_sec + !!my_timeval.tv_usec;
+ else
+ return 0;
+}
+
static __attribute__((unused))
int stat(const char *path, struct stat *buf)
{
--
2.20.1
Powered by blists - more mailing lists