summaryrefslogtreecommitdiff
path: root/timespec.h
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2015-06-04 16:21:34 -0700
committerGary E. Miller <gem@rellim.com>2015-06-04 16:21:34 -0700
commit271801553f4cd8da3b12c43a73f5a965cb1153f6 (patch)
tree3cee7cb211aeb1dc50fe29bd062aed5ffdef7716 /timespec.h
parent09200839cc0c8c8418adae9a5347b0a1fd5eacdc (diff)
downloadgpsd-271801553f4cd8da3b12c43a73f5a965cb1153f6.tar.gz
Remove duplicate definition of timespec_diff_ns()
Plus a logical reordering of things so more timespec stuff is in timespec.h
Diffstat (limited to 'timespec.h')
-rw-r--r--timespec.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/timespec.h b/timespec.h
index 2e918761..3d5f4cef 100644
--- a/timespec.h
+++ b/timespec.h
@@ -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 ) ||