X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ftime.h;h=e350cc998e8ae08ad5ac9527ddd670f971aaee37;hb=90ef7e4a2c6a41ec36bd2530b187cc1ef2cf0025;hp=a151505cbf2c12418adb441303d78c4d5efd947a;hpb=0354c8455147c6c31a2b43f3360acc9d046376a5;p=lttv.git diff --git a/ltt/branches/poly/ltt/time.h b/ltt/branches/poly/ltt/time.h index a151505c..e350cc99 100644 --- a/ltt/branches/poly/ltt/time.h +++ b/ltt/branches/poly/ltt/time.h @@ -178,5 +178,25 @@ static inline LttTime ltt_time_div(LttTime t1, double d) #endif //0 } +static inline guint64 ltt_time_to_uint64(LttTime t1) +{ + return (guint64)t1.tv_sec*NANOSECONDS_PER_SECOND + + (guint64)t1.tv_nsec; +} + + +#define MAX_TV_SEC_TO_UINT64 0x3FFFFFFFFFFFFFFFULL +static inline LttTime ltt_time_from_uint64(guint64 t1) +{ + /* We lose precision if tv_sec is > than (2^62)-1 + * */ + g_assert(t1 <= MAX_TV_SEC_TO_UINT64); + if(t1 > MAX_TV_SEC_TO_UINT64) + g_warning("Conversion from non precise uint64 to LttTime"); + LttTime res; + res.tv_sec = t1/NANOSECONDS_PER_SECOND; + res.tv_nsec = (t1 - res.tv_sec*NANOSECONDS_PER_SECOND); + return res; +} #endif // LTT_TIME_H