From 2eed866084e4553473f63951d89de4490ce0169c Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 7 Mar 2015 06:50:49 -0500 Subject: Revert "ntplib extraction requires libgpsd object format bump to 23." We need to sneak up on this in a more subtle way. --- SConstruct | 2 +- gpsd.c | 2 +- gpsd.h-tail | 3 ++- libgpsd_core.c | 14 ++++++++++---- ppsthread.c | 21 ++++++++++----------- ppsthread.h | 20 ++++++++++++-------- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/SConstruct b/SConstruct index c54557a2..6ec1727d 100644 --- a/SConstruct +++ b/SConstruct @@ -30,7 +30,7 @@ gpsd_version = "3.14~dev" libgps_version_current = 22 libgps_version_revision = 0 libgps_version_age = 0 -libgpsd_version_current = 23 +libgpsd_version_current = 22 libgpsd_version_revision = 0 libgpsd_version_age = 0 diff --git a/gpsd.c b/gpsd.c index 489d7e6d..ff42b7cb 100644 --- a/gpsd.c +++ b/gpsd.c @@ -1519,7 +1519,7 @@ static void all_reports(struct gps_device_t *device, gps_mask_t changed) //gpsd_report(&context.errout, LOG_PROG, "NTP: No time this packet\n"); } else if (isnan(device->newdata.time)) { //gpsd_report(&context.errout, LOG_PROG, "NTP: bad new time\n"); - } else if (device->newdata.time == device->pps_thread.fixin_real) { + } else if (device->newdata.time == device->last_fixtime.real) { //gpsd_report(&context.errout, LOG_PROG, "NTP: Not a new time\n"); } else if (!device->ship_to_ntpd) { //gpsd_report(&context.errout, LOG_PROG, "NTP: No precision time report\n"); diff --git a/gpsd.h-tail b/gpsd.h-tail index 911cd5d1..318ebf37 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -500,6 +500,7 @@ struct gps_device_t { volatile /*@null@*/ struct shmTime *shm_pps; # endif /* PPS_ENABLE */ #endif /* NTP_ENABLE */ + volatile struct pps_fixtime_t last_fixtime; /* so updates happen once */ #ifdef PPS_ENABLE #if defined(HAVE_SYS_TIMEPPS_H) pps_handle_t kernelpps_handle; @@ -508,7 +509,7 @@ struct gps_device_t { /*@null@*/ char *(*thread_report_hook)(struct gps_device_t *, struct timedelta_t *); /*@null@*/ void (*thread_wrap_hook)(struct gps_device_t *); - volatile struct pps_thread_t pps_thread; + struct pps_state_t pps_state; #endif /* PPS_ENABLE */ double mag_var; /* magnetic variation in degrees */ bool back_to_nmea; /* back to NMEA on revert? */ diff --git a/libgpsd_core.c b/libgpsd_core.c index 26560cb6..d9db154a 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -303,8 +303,11 @@ void gpsd_init(struct gps_device_t *session, struct gps_context_t *context, /* initialize GPS polling */ { /* clear some times */ + session->last_fixtime.real = 0.0; + /*@i2@*/session->last_fixtime.clock.tv_sec = 0; + /*@i2@*/session->last_fixtime.clock.tv_nsec = 0; #ifdef PPS_ENABLE - memset((void *)&session->pps_thread, 0, sizeof(session->pps_thread)); + memset((void *)&session->pps_state, 0, sizeof(session->pps_state)); #endif /* PPS_ENABLE */ /*@ -mayaliasunique @*/ @@ -397,9 +400,12 @@ void gpsd_clear(struct gps_device_t *session) /* clear the private data union */ memset( (void *)&session->driver, '\0', sizeof(session->driver)); -#ifdef PPS_ENABLE /* clear some times */ - memset((void *)&session->pps_thread, 0, sizeof(session->pps_thread)); + session->last_fixtime.real = 0.0; + /*@i2@*/session->last_fixtime.clock.tv_sec = 0; + /*@i2@*/session->last_fixtime.clock.tv_nsec = 0; +#ifdef PPS_ENABLE + memset((void *)&session->pps_state, 0, sizeof(session->pps_state)); #endif /* PPS_ENABLE */ session->opentime = timestamp(); @@ -1641,7 +1647,7 @@ void ntp_latch(struct gps_device_t *device, struct timedelta_t /*@out@*/*td) #ifdef PPS_ENABLE /* thread-safe update */ /*@-compdef@*/ - status = pps_thread_stash_fixtime(&device->pps_thread, + status = pps_thread_stash_fixtime(&device->last_fixtime, device->newdata.time, td->clock); /*@+compdef@*/ if (status == PPS_LOCK_ERR) { diff --git a/ppsthread.c b/ppsthread.c index ff25b81c..52512bc8 100644 --- a/ppsthread.c +++ b/ppsthread.c @@ -350,8 +350,8 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) "PPS: pthread_mutex_lock() : %s\n", errbuf); } /*@ +unrecog @*/ - last_fixtime_real = session->pps_thread.fixin_real; - last_fixtime_clock = session->pps_thread.fixin_clock; + last_fixtime_real = session->last_fixtime.real; + last_fixtime_clock = session->last_fixtime.clock; /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); if ( 0 != pthread_err ) { @@ -704,9 +704,9 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) } /*@ +unrecog @*/ /*@-type@*/ /* splint is confused about struct timespec */ - session->pps_thread.ppsout_last = ppstimes; + session->pps_state.ppslast = ppstimes; /*@+type@*/ - session->pps_thread.ppsout_count++; + session->pps_state.ppscount++; /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); if ( 0 != pthread_err ) { @@ -787,7 +787,7 @@ void pps_thread_deactivate(struct gps_device_t *session) /*@+nullstate +mustfreeonly@*/ } -int pps_thread_stash_fixtime(volatile struct pps_thread_t *pps_thread, +int pps_thread_stash_fixtime(volatile struct pps_fixtime_t *last_fixtime, timestamp_t realtime, struct timespec clocktime) /* thread-safe update of last fix time - only way we pass data in */ { @@ -799,8 +799,8 @@ int pps_thread_stash_fixtime(volatile struct pps_thread_t *pps_thread, ret = PPS_LOCK_ERR; else { /*@ +unrecog @*/ - pps_thread->fixin_real = realtime; - pps_thread->fixin_clock = clocktime; + last_fixtime->real = realtime; + last_fixtime->clock = clocktime; } /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); @@ -811,8 +811,7 @@ int pps_thread_stash_fixtime(volatile struct pps_thread_t *pps_thread, return ret; } -int pps_thread_lastpps(volatile struct pps_thread_t *pps_thread, - struct timedelta_t *td) +int pps_thread_lastpps(struct pps_state_t *pps_state, struct timedelta_t *td) /* return the delta at the time of the last PPS - only way we pass data out */ { volatile int ret; @@ -825,8 +824,8 @@ int pps_thread_lastpps(volatile struct pps_thread_t *pps_thread, ret = PPS_LOCK_ERR; else { /*@ +unrecog @*/ - *td = pps_thread->ppsout_last; - ret = pps_thread->ppsout_count; + *td = pps_state->ppslast; + ret = pps_state->ppscount; } /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); diff --git a/ppsthread.h b/ppsthread.h index 719239aa..ae7bd886 100644 --- a/ppsthread.h +++ b/ppsthread.h @@ -22,21 +22,25 @@ struct timedelta_t { #define HAVE_TIMEDELTA #endif /* HAVE_TIMEDELTA */ -struct pps_thread_t { - timestamp_t fixin_real; - struct timespec fixin_clock; /* system clock time when last fix received */ - struct timedelta_t ppsout_last; - int ppsout_count; +struct pps_state_t { + volatile struct timedelta_t ppslast; + volatile int ppscount; +}; + +struct pps_fixtime_t { + timestamp_t real; + /* clock must be a timespec as it is in nSec and + * a timestamp_t will lose precision */ + struct timespec clock; /* system clock time when last fix received */ }; #define PPS_THREAD_OK 0 #define PPS_LOCK_ERR -1 #define PPS_UNLOCK_ERR -2 -extern int pps_thread_stash_fixtime(volatile struct pps_thread_t *, +extern int pps_thread_stash_fixtime(volatile struct pps_fixtime_t *, timestamp_t, struct timespec); -extern int pps_thread_lastpps(volatile struct pps_thread_t *, - struct timedelta_t *); +extern int pps_thread_lastpps(struct pps_state_t *, struct timedelta_t *); #endif /* PPSTHREAD_H */ -- cgit v1.2.1