[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] lib/nolibc: add sleep()



sleep() can be implemented as a simple wrapper around nanosleep(), and
it's quite convenient for writing quick test apps.

Signed-off-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>
---
 lib/nolibc/exportsyms.uk    |  3 +++
 lib/nolibc/include/unistd.h |  2 ++
 lib/nolibc/time.c           | 12 ++++++++++++
 3 files changed, 17 insertions(+)

diff --git a/lib/nolibc/exportsyms.uk b/lib/nolibc/exportsyms.uk
index f3f23058..cae6e298 100644
--- a/lib/nolibc/exportsyms.uk
+++ b/lib/nolibc/exportsyms.uk
@@ -74,6 +74,9 @@ strlcat
 nanosleep
 clock_gettime
 
+# unistd
+sleep
+
 # sys/time
 gettimeofday
 
diff --git a/lib/nolibc/include/unistd.h b/lib/nolibc/include/unistd.h
index 9881ab5b..de0356f1 100644
--- a/lib/nolibc/include/unistd.h
+++ b/lib/nolibc/include/unistd.h
@@ -47,6 +47,8 @@ extern "C" {
 #define __NEED_ssize_t
 #include <nolibc-internal/shareddefs.h>
 
+unsigned int sleep(unsigned int seconds);
+
 #if CONFIG_LIBVFSCORE
 int close(int fd);
 ssize_t write(int fd, const void *buf, size_t count);
diff --git a/lib/nolibc/time.c b/lib/nolibc/time.c
index 69f29300..f884531f 100644
--- a/lib/nolibc/time.c
+++ b/lib/nolibc/time.c
@@ -92,6 +92,18 @@ int nanosleep(const struct timespec *req, struct timespec 
*rem)
        return 0;
 }
 
+unsigned int sleep(unsigned int seconds)
+{
+       struct timespec ts;
+
+       ts.tv_sec = seconds;
+       ts.tv_nsec = 0;
+       if (nanosleep(&ts, &ts))
+               return ts.tv_sec;
+
+       return 0;
+}
+
 int gettimeofday(struct timeval *tv, void *tz __unused)
 {
        __nsec now = ukplat_wall_clock();
-- 
2.21.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.