summaryrefslogtreecommitdiff
path: root/ppsthread.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-04-01 05:32:43 -0400
committerEric S. Raymond <esr@thyrsus.com>2015-04-01 05:32:43 -0400
commite498ed8029b4488eb09436df0716bc12a076c161 (patch)
tree0267b90730fdc54f9ca4aebd19738bb6e14c979b /ppsthread.c
parentc9c304581d7b98989a6831e5a49bf69cf085c1a7 (diff)
downloadgpsd-e498ed8029b4488eb09436df0716bc12a076c161.tar.gz
Eliminate some duplication code for timespec arithmetic.
Diffstat (limited to 'ppsthread.c')
-rw-r--r--ppsthread.c48
1 files changed, 1 insertions, 47 deletions
diff --git a/ppsthread.c b/ppsthread.c
index 16b468a8..3425dcda 100644
--- a/ppsthread.c
+++ b/ppsthread.c
@@ -75,7 +75,7 @@
#include <sys/timepps.h>
#endif
-#include "timespec_str.h"
+#include "timespec.h"
#include "ppsthread.h"
/*
@@ -130,52 +130,6 @@ static int get_edge_rfc2783(struct inner_context_t *,
volatile struct timedelta_t *);
#endif /* defined(HAVE_SYS_TIMEPPS_H) */
-/* normalize a timespec
- *
- * three cases to note
- * if tv_sec is positve, then tv_nsec must be positive
- * if tv_sec is negative, then tv_nsec must be negative
- * if tv_sec is zero, then tv_nsec may be positive or negative.
- *
- * this only handles the case where two normalized timespecs
- * are added or subracted. (e.g. only a one needs to be borrowed/carried
- */
-static inline void TS_NORM( struct timespec *ts)
-{
- if ( ( 1 <= ts->tv_sec ) ||
- ( (0 == ts->tv_sec ) && (0 <= ts->tv_nsec ) ) ) {
- /* result is positive */
- if ( 1000000000 <= ts->tv_nsec ) {
- /* borrow from tv_sec */
- ts->tv_nsec -= 1000000000;
- ts->tv_sec++;
- } else if ( 0 > (ts)->tv_nsec ) {
- /* carry to tv_sec */
- ts->tv_nsec += 1000000000;
- ts->tv_sec--;
- }
- } else {
- /* result is negative */
- if ( -1000000000 >= ts->tv_nsec ) {
- /* carry to tv_sec */
- ts->tv_nsec += 1000000000;
- ts->tv_sec--;
- } else if ( 0 < ts->tv_nsec ) {
- /* borrow from tv_sec */
- ts->tv_nsec -= 1000000000;
- ts->tv_sec++;
- }
- }
-}
-
-/* subtract two timespec */
-#define TS_SUB(r, ts1, ts2) \
- do { \
- (r)->tv_sec = (ts1)->tv_sec - (ts2)->tv_sec; \
- (r)->tv_nsec = (ts1)->tv_nsec - (ts2)->tv_nsec; \
- TS_NORM( r ); \
- } while (0)
-
static pthread_mutex_t ppslast_mutex = PTHREAD_MUTEX_INITIALIZER;
static void thread_lock(volatile struct pps_thread_t *pps_thread)