diff options
-rw-r--r-- | gpsd.h-tail | 3 | ||||
-rw-r--r-- | libgps_shm.c | 14 | ||||
-rw-r--r-- | ntpshm.c | 6 | ||||
-rw-r--r-- | shmexport.c | 6 |
4 files changed, 14 insertions, 15 deletions
diff --git a/gpsd.h-tail b/gpsd.h-tail index 10b68f32..4c18d9ef 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -999,8 +999,7 @@ void cfmakeraw(struct termios *); /* Needed because 4.x versions of GCC are really annoying */ #define ignore_return(funcall) assert(funcall != -23) -/* memory barriers */ -static /*@unused@*/ inline void barrier(void) +static /*@unused@*/ inline void memory_barrier(void) { #ifndef S_SPLINT_S #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) diff --git a/libgps_shm.c b/libgps_shm.c index 88b340e8..5f79aee2 100644 --- a/libgps_shm.c +++ b/libgps_shm.c @@ -75,10 +75,10 @@ bool gps_shm_waiting(const struct gps_data_t *gpsdata, int timeout) /* busy-waiting sucks, but there's not really an alternative */ for (;;) { bool newdata = false; - barrier(); + memory_barrier(); if (shared->bookend1 == shared->bookend2 && shared->bookend1 > PRIVATE(gpsdata)->tick) newdata = true; - barrier(); + memory_barrier(); if (newdata || (timestamp() - basetime >= (double)timeout)) break; } @@ -100,9 +100,9 @@ int gps_shm_read(struct gps_data_t *gpsdata) struct gps_data_t noclobber; /* - * Following block of instructions must not be reordered, otherwise - * havoc will ensue. The barrier() call should prevent reordering - * of the data accesses. + * Following block of instructions must not be reordered, + * otherwise havoc will ensue. The memory_barrier() call + * should prevent reordering of the data accesses. * * This is a simple optimistic-concurrency technique. We wrote * the second bookend first, then the data, then the first bookend. @@ -111,11 +111,11 @@ int gps_shm_read(struct gps_data_t *gpsdata) * get clobbered first and the data can be detected as bad. */ before = shared->bookend1; - barrier(); + memory_barrier(); (void)memcpy((void *)&noclobber, (void *)&shared->gpsdata, sizeof(struct gps_data_t)); - barrier(); + memory_barrier(); after = shared->bookend2; if (before != after) @@ -227,7 +227,7 @@ int ntpshm_put(struct gps_device_t *session, int shmIndex, struct timedrift_t *t /* * shmTime is volatile to try to prevent C compiler from reordering * writes, or optimizing some 'dead code'. but CPU cache may still - * write out of order if barrier() is a no-op (our implementation + * write out of order if memory_barrier() is a no-op (our implementation * isn't portable). */ volatile struct shmTime *shmTime = NULL; @@ -264,7 +264,7 @@ int ntpshm_put(struct gps_device_t *session, int shmIndex, struct timedrift_t *t shmTime->count++; /* We need a memory barrier here to prevent write reordering by * the compiler or CPU cache */ - barrier(); + memory_barrier(); /*@-type@*/ /* splint is confused about struct timespec */ shmTime->clockTimeStampSec = (time_t)td->real.tv_sec; shmTime->clockTimeStampUSec = (int)(td->real.tv_nsec/1000); @@ -275,7 +275,7 @@ int ntpshm_put(struct gps_device_t *session, int shmIndex, struct timedrift_t *t /*@+type@*/ shmTime->leap = session->context->leap_notify; shmTime->precision = precision; - barrier(); + memory_barrier(); shmTime->count++; shmTime->valid = 1; diff --git a/shmexport.c b/shmexport.c index 1baadd4e..3b764b57 100644 --- a/shmexport.c +++ b/shmexport.c @@ -80,17 +80,17 @@ void shm_update(struct gps_context_t *context, struct gps_data_t *gpsdata) * get clobbered first and the data can be detected as bad. */ shared->bookend2 = tick; - barrier(); + memory_barrier(); memcpy((void *)(context->shmexport + offsetof(struct shmexport_t, gpsdata)), (void *)gpsdata, sizeof(struct gps_data_t)); - barrier(); + memory_barrier(); #ifndef USE_QT shared->gpsdata.gps_fd = SHM_PSEUDO_FD; #else shared->gpsdata.gps_fd = (void *)(intptr_t)SHM_PSEUDO_FD; #endif /* USE_QT */ - barrier(); + memory_barrier(); shared->bookend1 = tick; } } |