00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #ifndef _time_util_h
00019 #define _time_util_h
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 #include "assert_pp.h"
00026 
00027 
00028 
00029 
00030 #define MICROS_PER_SECOND 1000000
00031 
00032 
00033 
00034 
00035 #define NANOS_PER_MICRO 1000
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 static inline
00044 struct timespec microsec_to_timespec(unsigned long long microseconds)
00045 {
00046     struct timespec retval;
00047     
00048     retval.tv_sec =  (int)(microseconds / MICROS_PER_SECOND);
00049     retval.tv_nsec = (int)(microseconds % MICROS_PER_SECOND) * NANOS_PER_MICRO;
00050     return retval;
00051 }
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 static inline
00061 unsigned long long timespec_to_microsec(struct timespec *time_spec)
00062 {
00063     long long retval;
00064 
00065     require(time_spec != 0);
00066     
00067     retval = time_spec->tv_sec * MICROS_PER_SECOND;
00068     retval += time_spec->tv_nsec / NANOS_PER_MICRO;
00069     return retval;
00070 }
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 int string_to_microsec(unsigned long long *us_out, const char *str);
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 #define tscmp(tvp, uvp, cmp)                                            \
00096         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
00097             ((tvp)->tv_nsec cmp (uvp)->tv_nsec) :                       \
00098             ((tvp)->tv_sec cmp (uvp)->tv_sec))
00099 
00100 #ifdef __cplusplus
00101 }
00102 #endif
00103 
00104 #endif