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

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat Sep 20 23:06:02 2014 +0200

lib/cobalt: wrap time and gettimeofday calls

---

 include/cobalt/time.h       |    2 ++
 lib/cobalt/assert_context.c |    7 -------
 lib/cobalt/clock.c          |   23 +++++++++++++++++++++++
 lib/cobalt/cobalt.wrappers  |    1 +
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/include/cobalt/time.h b/include/cobalt/time.h
index c5d7412..fed8957 100644
--- a/include/cobalt/time.h
+++ b/include/cobalt/time.h
@@ -44,6 +44,8 @@ COBALT_DECL(int, clock_nanosleep(clockid_t clock_id,
                                 const struct timespec *rqtp,
                                 struct timespec *rmtp));
 
+COBALT_DECL(time_t, time(time_t *t));
+
 COBALT_DECL(int, nanosleep(const struct timespec *rqtp,
                           struct timespec *rmtp));
 
diff --git a/lib/cobalt/assert_context.c b/lib/cobalt/assert_context.c
index 6b49f3d..48690dc 100644
--- a/lib/cobalt/assert_context.c
+++ b/lib/cobalt/assert_context.c
@@ -75,10 +75,3 @@ COBALT_IMPL(void, free, (void *ptr))
        assert_nrt();
        __STD(free(ptr));
 }
-
-/* vsyscall-based services */
-COBALT_IMPL(int, gettimeofday, (struct timeval *tv, struct timezone *tz))
-{
-       assert_nrt();
-       return __STD(gettimeofday(tv, tz));
-}
diff --git a/lib/cobalt/clock.c b/lib/cobalt/clock.c
index b31517f..d17ea56 100644
--- a/lib/cobalt/clock.c
+++ b/lib/cobalt/clock.c
@@ -25,6 +25,7 @@
 #include <pthread.h>
 #include <unistd.h>
 #include <time.h>
+#include <sys/time.h>
 #include <cobalt/uapi/time.h>
 #include <cobalt/ticks.h>
 #include <asm/xenomai/syscall.h>
@@ -356,4 +357,26 @@ COBALT_IMPL(unsigned int, sleep, (unsigned int seconds))
        return 0;
 }
 
+COBALT_IMPL(int, gettimeofday, (struct timeval *tv, struct timezone *tz))
+{
+       struct timespec ts;
+       int ret = __WRAP(clock_gettime(CLOCK_REALTIME, &ts));
+       if (ret == 0) {
+               tv->tv_sec = ts.tv_sec;
+               tv->tv_usec = ts.tv_nsec / 1000;
+       }
+       return ret;
+}
+
+COBALT_IMPL(time_t, time, (time_t *t))
+{
+       struct timespec ts;
+       int ret = __WRAP(clock_gettime(CLOCK_REALTIME, &ts));
+       if (ret)
+               return (time_t)-1;
+
+       if (t)
+               *t = ts.tv_sec;
+       return ts.tv_sec;
+}
 /** @} */
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 10cb36a..329ff3b 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -104,3 +104,4 @@
 --wrap kill
 --wrap sleep
 --wrap mmap
+--wrap time


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

Reply via email to