summaryrefslogtreecommitdiff
path: root/ntpshm.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-02-15 21:33:35 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-02-15 21:33:35 -0500
commitd3521ce59ba8065ca6e65f95787fcb7d6b0ac60d (patch)
treeddf71d83a5e81c6c386a71928b8f2d0e55d5444d /ntpshm.c
parent8c32e095b3e70f1aea13d7f16aad29eea9746626 (diff)
downloadgpsd-d3521ce59ba8065ca6e65f95787fcb7d6b0ac60d.tar.gz
Simplify NTP SHM segment creation.
This will avoid an object file compatibility break later. All regression tetrs pass. SHM segments allocate successfully in live testing.
Diffstat (limited to 'ntpshm.c')
-rw-r--r--ntpshm.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/ntpshm.c b/ntpshm.c
index d06ccb5d..e5a6b3c2 100644
--- a/ntpshm.c
+++ b/ntpshm.c
@@ -32,7 +32,6 @@
#include <sys/shm.h>
#define NTPD_BASE 0x4e545030 /* "NTP0" */
-#define SHM_UNIT 0 /* SHM driver unit number (0..3) */
#define PPS_MIN_FIXES 3 /* # fixes to wait for before shipping PPS */
@@ -92,6 +91,9 @@ struct shmTime
* GPS will deliver data on segments 0 and 1, and as non-root data
* will be delivered on segments 2 and 3.
*
+ * We use dummy[0] as an in-use flag, so segments can be released and
+ * reallocated from holes in the sequence.
+ *
* to debug, try looking at the live segments this way
*
* ipcs -m
@@ -172,7 +174,6 @@ void ntpshm_context_init(struct gps_context_t *context)
context->shmTime[i] = getShmTime(context, i);
}
}
- memset(context->shmTimeInuse, 0, sizeof(context->shmTimeInuse));
}
/*@-unqualifiedtrans@*/
@@ -182,8 +183,8 @@ static /*@null@*/ volatile struct shmTime *ntpshm_alloc(struct gps_context_t *co
int i;
for (i = 0; i < NTPSHMSEGS; i++)
- if (context->shmTime[i] != NULL && !context->shmTimeInuse[i]) {
- context->shmTimeInuse[i] = true;
+ if (context->shmTime[i] != NULL && !context->shmTime[i]->dummy[0] != 0) {
+ context->shmTime[i]->dummy[0] = (char)true;
/*
* In case this segment gets sent to ntpd before an
@@ -213,7 +214,7 @@ static bool ntpshm_free(struct gps_context_t * context, volatile struct shmTime
for (i = 0; i < NTPSHMSEGS; i++)
if (s == context->shmTime[i]) {
- context->shmTimeInuse[i] = false;
+ context->shmTime[i]->dummy[0] = (char)false;
return true;
}