Module: xenomai-gch
Branch: for-forge
Commit: 7b891e43a22f939a5010d975984f4f6d87c2eda4
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=7b891e43a22f939a5010d975984f4f6d87c2eda4

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  |    2 ++
 4 files changed, 27 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 501cdec..b35dfd4 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..b8c9942 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -104,3 +104,5 @@
 --wrap kill
 --wrap sleep
 --wrap mmap
+--wrap gettimeofday
+--wrap time


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

Reply via email to