From 444d8c6140e15a919278d940035a58ccdddbfd00 Mon Sep 17 00:00:00 2001 From: sangorrin Date: Mon, 23 Jul 2007 17:34:28 +0000 Subject: [PATCH] added two functions that were in another file git-svn-id: http://www.frescor.org/private/svn/frescor/frsh/trunk/include@580 35b4ef3e-fd22-0410-ab77-dab3279adceb --- timespec_operations.h | 52 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/timespec_operations.h b/timespec_operations.h index a816847..a384d2c 100644 --- a/timespec_operations.h +++ b/timespec_operations.h @@ -95,7 +95,8 @@ * *---------------------------------------------------------------------------*/ // 16-Jul-2007 SANGORRIN corrections to msec_addto_timespec and msec2timespec -// (TODO: test the rest of functions) +// 23-Jul-2007 SANGORRIN moved t2d and d2t from frsh_time_operations +// (TODO: test for __ALL__ the functions) // ----------------------------------------------------------------------- #ifndef _MARTE_MISC_TIMESPEC_OPERATIONS_H_ @@ -105,18 +106,19 @@ * @file timespec_operations.h **/ -#include +#include // for timespec +#include // for memset #define smaller_timespec(t1, t2) \ ( \ (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \ - (t1)->tv_nsec < (t2)->tv_nsec) \ + (t1)->tv_nsec < (t2)->tv_nsec) \ ) #define smaller_or_equal_timespec(t1, t2) \ ( \ (t1)->tv_sec < (t2)->tv_sec || ((t1)->tv_sec == (t2)->tv_sec && \ - (t1)->tv_nsec <= (t2)->tv_nsec) \ + (t1)->tv_nsec <= (t2)->tv_nsec) \ ) #define incr_timespec(t1, t2) \ @@ -140,7 +142,6 @@ do { \ } \ } while (0) - #define add_timespec( sum , t1 , t2 ) \ do { \ (sum)->tv_sec = (t1)->tv_sec + (t2)->tv_sec; \ @@ -165,9 +166,11 @@ do { \ (t1) \ ) -#include /* for memset */ +//---------------// +// msec2timespec // +//---------------// -static void inline msec2timespec(long msec, struct timespec *timespec) +static inline void msec2timespec(long msec, struct timespec *timespec) { memset(timespec, 0, sizeof(struct timespec)); @@ -180,9 +183,11 @@ static void inline msec2timespec(long msec, struct timespec *timespec) } } -/* ------------------------------------------------------------ */ +//------------------------// +// timespec_lessthan_msec // +//------------------------// -static int inline timespec_lessthan_msec(struct timespec *timespec, long msec) +static inline int timespec_lessthan_msec(struct timespec *timespec, long msec) { struct timespec msec_timespec = {0, 0}; @@ -190,9 +195,11 @@ static int inline timespec_lessthan_msec(struct timespec *timespec, long msec) return smaller_timespec(timespec, &msec_timespec); } -/* ------------------------------------------------------------ */ +//---------------------// +// msec_addto_timespec // +//---------------------// -static void inline msec_addto_timespec(long msec, struct timespec *timespec) +static inline void msec_addto_timespec(long msec, struct timespec *timespec) { struct timespec msec_timespec = {0, 0}; @@ -200,4 +207,27 @@ static void inline msec_addto_timespec(long msec, struct timespec *timespec) incr_timespec(timespec, &msec_timespec); } +//--------------------------// +// t2d (timespec to double) // +//--------------------------// + +static inline double t2d(struct timespec time) +{ + return time.tv_nsec*0.000000001 + (double)time.tv_sec; +} + +//--------------------------// +// d2t (double to timespec) // +//--------------------------// + +static inline struct timespec d2t(double time) +{ + struct timespec tmp; + + tmp.tv_sec = (long) time; + tmp.tv_nsec = (long)((time - (double)tmp.tv_sec) * 1000000000); + + return tmp; +} + #endif /* _MARTE_MISC_TIMESPEC_OPERATIONS_H_ */ -- 2.39.2