diff options
author | Mark Brown <broonie@kernel.org> | 2021-05-12 13:32:15 +0100 |
---|---|---|
committer | Willy Tarreau <w@1wt.eu> | 2021-05-12 15:19:00 +0200 |
commit | 6d538c75a61aa72ab6dcdc4ee9d79d994918ad19 (patch) | |
tree | 9cdc43ed98172916fd139ca29b6c2aa211e2185b | |
parent | 2fa743da76561f2f1b9eb5795e83ba91f95cd62f (diff) | |
download | cleanups-nolibc.tar.gz |
tools/nolibc: Implement msleep()nolibc
Allow users to implement shorter delays than a full second by implementing
msleep().
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
-rw-r--r-- | tools/include/nolibc/nolibc.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/include/nolibc/nolibc.h b/tools/include/nolibc/nolibc.h index 13c194aeaf3f02..3430667b0d241d 100644 --- a/tools/include/nolibc/nolibc.h +++ b/tools/include/nolibc/nolibc.h @@ -2244,6 +2244,19 @@ unsigned int sleep(unsigned int seconds) } 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) { int ret = sys_stat(path, buf); |