Module: xenomai-3
Branch: next
Commit: ae5beba2779c127c4e46b193add83b9fa3ad65a8
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=ae5beba2779c127c4e46b193add83b9fa3ad65a8

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Mon May 30 14:58:07 2016 +0200

lib/cobalt: Provide RT-capable usleep

User may expect this (probably last) sleeping service to be available
under Cobalt just like sleep, nanosleep & Co.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/cobalt/unistd.h    |    2 ++
 lib/cobalt/clock.c         |   14 ++++++++++++++
 lib/cobalt/cobalt.wrappers |    1 +
 lib/cobalt/wrappers.c      |    6 ++++++
 4 files changed, 23 insertions(+)

diff --git a/include/cobalt/unistd.h b/include/cobalt/unistd.h
index 8ad2b40..fe3992a 100644
--- a/include/cobalt/unistd.h
+++ b/include/cobalt/unistd.h
@@ -35,6 +35,8 @@ COBALT_DECL(int, close(int fildes));
 
 COBALT_DECL(unsigned int, sleep(unsigned int seconds));
 
+COBALT_DECL(int, usleep(useconds_t usec));
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index 0450019..7b4ef54 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -364,6 +364,20 @@ COBALT_IMPL(unsigned int, sleep, (unsigned int seconds))
        return 0;
 }
 
+/* @apitags{thread-unrestricted, switch-primary} */
+
+COBALT_IMPL(int, usleep, (useconds_t usec))
+{
+       struct timespec rqt;
+
+       if (cobalt_get_current_fast() == XN_NO_HANDLE)
+               return __STD(usleep(usec));
+
+       rqt.tv_sec = usec / 1000000;
+       rqt.tv_nsec = (usec % 1000000) * 1000;
+       return __WRAP(clock_nanosleep(CLOCK_MONOTONIC, 0, &rqt, NULL));
+}
+
 /* @apitags{unrestricted} */
 
 COBALT_IMPL(int, gettimeofday, (struct timeval *tv, struct timezone *tz))
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index f8bda39..91bd5ef 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -108,6 +108,7 @@
 --wrap sigqueue
 --wrap kill
 --wrap sleep
+--wrap usleep
 --wrap mmap
 --wrap mmap64
 --wrap time
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 8dd28fb..0507786 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -529,3 +529,9 @@ unsigned int __real_sleep(unsigned int seconds)
 {
        return sleep(seconds);
 }
+
+__weak
+int __real_usleep(useconds_t usec)
+{
+       return usleep(usec);
+}


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to