2021-05-12 12:53:03

by Mark Brown

[permalink] [raw]
Subject: [PATCH v3] tools/nolibc: Implement msleep()

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

Signed-off-by: Mark Brown <[email protected]>
---
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(+)

diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h
index 8b7a9830dd22..ba6b6f1ad846 100644
--- a/tools/include/nolibc/nolibc.h
+++ b/tools/include/nolibc/nolibc.h
@@ -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)
{
--
2.20.1


2021-05-12 13:22:40

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH v3] tools/nolibc: Implement msleep()

On Wed, May 12, 2021 at 01:32:15PM +0100, Mark Brown wrote:
> Allow users to implement shorter delays than a full second by implementing
> msleep().
>
> Signed-off-by: Mark Brown <[email protected]>

Great, now queued, thank you Mark!
Willy

2021-06-22 16:49:58

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3] tools/nolibc: Implement msleep()

On Wed, May 12, 2021 at 03:21:02PM +0200, Willy Tarreau wrote:
> On Wed, May 12, 2021 at 01:32:15PM +0100, Mark Brown wrote:
> > Allow users to implement shorter delays than a full second by implementing
> > msleep().
> >
> > Signed-off-by: Mark Brown <[email protected]>

> 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?


Attachments:
(No filename) (425.00 B)
signature.asc (499.00 B)
Download all attachments

2021-06-22 16:53:28

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH v3] tools/nolibc: Implement msleep()

Hi Mark,

On Tue, Jun 22, 2021 at 05:48:04PM +0100, Mark Brown wrote:
> On Wed, May 12, 2021 at 03:21:02PM +0200, Willy Tarreau wrote:
> > On Wed, May 12, 2021 at 01:32:15PM +0100, Mark Brown wrote:
> > > Allow users to implement shorter delays than a full second by implementing
> > > msleep().
> > >
> > > Signed-off-by: Mark Brown <[email protected]>
>
> > 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