diff options
-rw-r--r-- | ntpshmmon.c | 6 | ||||
-rw-r--r-- | ppsthread.h | 5 | ||||
-rw-r--r-- | timespec.h | 7 |
3 files changed, 8 insertions, 10 deletions
diff --git a/ntpshmmon.c b/ntpshmmon.c index 56f90aa6..ce30cd28 100644 --- a/ntpshmmon.c +++ b/ntpshmmon.c @@ -13,14 +13,10 @@ #include "gpsd_config.h" #include "ntpshm.h" #include "revision.h" +#include "timespec.h" #define NTPSEGMENTS 256 /* NTPx for x any byte */ -/* difference between timespecs in nanoseconds */ -/* int is too small, 32 bit long is too small, avoid floats */ -/* MUST be long long to maintain precision on 32 bit code */ -#define timespec_diff_ns(x, y) (long long)(((x).tv_sec-(y).tv_sec)*1000000000LL+(x).tv_nsec-(y).tv_nsec) - static struct shmTime *segments[NTPSEGMENTS + 1]; static struct timespec tick[NTPSEGMENTS + 1]; diff --git a/ppsthread.h b/ppsthread.h index 58d4b31a..b37e739c 100644 --- a/ppsthread.h +++ b/ppsthread.h @@ -16,11 +16,6 @@ struct timedelta_t { }; #endif /* TIMEDELTA_DEFINED */ -/* difference between timespecs in nanoseconds */ -/* int is too small, 32 bit long is too small, avoid floats */ -/* MUST be long long to maintain precision on 32 bit code */ -#define timespec_diff_ns(x, y) (long long)(((x).tv_sec-(y).tv_sec)*1000000000LL+(x).tv_nsec-(y).tv_nsec) - /* * Set context, devicefd, and devicename at initialization time, before * you call pps_thread_activate(). The context pointer can be used to @@ -21,6 +21,13 @@ #define NS_IN_SEC 1000000000 #define MS_IN_SEC 1000000 +/* return the difference between timespecs in nanoseconds + * int may be too small, 32 bit long is too small, floats are too imprecise, + * doubles are not quite precise enough + * MUST be long long to maintain precision on 32 bit code */ +#define timespec_diff_ns(x, y) \ + (long long)((((x).tv_sec-(y).tv_sec)*NS_IN_SEC)+(x).tv_nsec-(y).tv_nsec) + static inline void TS_NORM( struct timespec *ts) { if ( ( 1 <= ts->tv_sec ) || |