diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-03-27 13:39:09 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-03-27 13:39:09 -0400 |
commit | 4eea65f0cd06ecd356fc371e707cda174537e616 (patch) | |
tree | a295b45bbf634a1ebe52ae6152920368fa327f4e | |
parent | 8118ed642d8d2d046684d5ce596206698127dc4b (diff) | |
download | gpsd-4eea65f0cd06ecd356fc371e707cda174537e616.tar.gz |
Change return values in the shm interface to be more like socket export.
All regression tests pass. Code splints clean. shm live-testing works.
-rw-r--r-- | gpsd.h-tail | 2 | ||||
-rw-r--r-- | gpxlogger.c | 11 | ||||
-rw-r--r-- | libgps_shm.c | 2 | ||||
-rw-r--r-- | shmexport.c | 6 |
4 files changed, 14 insertions, 7 deletions
diff --git a/gpsd.h-tail b/gpsd.h-tail index bd859e8f..2174d86c 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -759,7 +759,7 @@ void cfmakeraw(struct termios *); #define DEVICEHOOKPATH SYSCONFDIR"/gpsd/device-hook" /* memory barriers */ -static inline void barrier(void) { +static /*@unused@*/ inline void barrier(void) { #ifdef __GNUC__ #ifndef S_SPLINT_S asm volatile("sfence"); diff --git a/gpxlogger.c b/gpxlogger.c index 2bab9270..2d6c9a90 100644 --- a/gpxlogger.c +++ b/gpxlogger.c @@ -351,10 +351,15 @@ static int shm_mainloop(void) print_gpx_header(); for (;;) { - (void)gps_shm_read(&gpsdata); - conditionally_log_fix(&gpsdata); + status = gps_shm_read(&gpsdata); + + if (status == -1) + break; + if (status > 0) + conditionally_log_fix(&gpsdata); } - /* (void)gps_shm_close(&gpsdata); */ + (void)gps_shm_close(&gpsdata); + return 0; } /*@+mustfreefresh +compdestroy@*/ diff --git a/libgps_shm.c b/libgps_shm.c index 8c90f524..99457842 100644 --- a/libgps_shm.c +++ b/libgps_shm.c @@ -74,7 +74,7 @@ int gps_shm_read(struct gps_data_t *gpsdata) after = shared->bookend2; /*@i1@*/gpsdata->privdata = shared; - return (before == after) ? 0 : -1; + return (before == after) ? sizeof(struct gps_data_t) : 0; } } diff --git a/shmexport.c b/shmexport.c index 4d615abf..c79d4c08 100644 --- a/shmexport.c +++ b/shmexport.c @@ -63,6 +63,7 @@ void shm_update(struct gps_context_t *context, struct gps_data_t *gpsdata) if (context->shmexport != NULL) { static int tick; + struct shmexport_t *shared = (struct shmexport_t *)context->shmexport; ++tick; /* @@ -76,13 +77,14 @@ void shm_update(struct gps_context_t *context, struct gps_data_t *gpsdata) * start to write the segment during the read, the second bookend will * get clobbered first and the data can be detected as bad. */ - ((struct shmexport_t *)context->shmexport)->bookend2 = tick; + shared->bookend2 = tick; barrier(); memcpy((void *)(context->shmexport + offsetof(struct shmexport_t, gpsdata)), (void *)gpsdata, sizeof(struct gps_data_t)); + shared->gpsdata.gps_fd = -1; barrier(); - ((struct shmexport_t *)context->shmexport)->bookend1 = tick; + shared->bookend1 = tick; } } |