Skip to contentSkip to conversation

tools/nolibc: Implement msleep()

PATCH In review Mark Brown 2 participants 4 messages May 12, 2021 – Jun 22, 2021 Nolibc header file

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH v3 1/1 tools/nolibc: Implement msleep()

Allow users to implement shorter delays than a full second by implementing msleep().

---
v3:
- Return the number of milliseconds remaining if the delay does not complete.
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 | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/include/nolibc/nolibc.h +13 -0
index 8b7a9830dd22..ba6b6f1ad846 100644
@@ -2243,6 +2243,19 @@ 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 * 1000) +
+			(my_timeval.tv_usec / 1000) +
+			!!(my_timeval.tv_usec % 1000);
+	else
+		return 0;
+}
+
 static __attribute__((unused))
 int stat(const char *path, struct stat *buf)
 {
Signature · 1 line
2.20.1
author
#2 lore raw
Quoted 7 lines · Willy Tarreau
Quoted 4 lines · Mark Brown

Allow users to implement shorter delays than a full second by implementing msleep().

Great, now queued, thank you Mark!

This doesn't seem to be showing up in -next, did it get missed or is the queue it's in not in -next?

maintainer
#3 lore raw

Hi Mark,

Quoted 11 lines · Mark Brown
Quoted 7 lines · Willy Tarreau
Quoted 4 lines · Mark Brown

Allow users to implement shorter delays than a full second by implementing msleep().

Great, now queued, thank you Mark!

This doesn't seem to be showing up in -next, did it get missed or is the queue it's in not in -next?

I planned to send the two patches I have in this branch to Paul this week, will do so ASAP.

Thanks,
Willy