summary refs log tree commit diff
path: root/ring.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-25 03:04:45 -0400
committerJune McEnroe <june@causal.agency>2019-10-25 03:04:45 -0400
commit243a5f930dce0cddd54d7d927774f7ad82b3d88e (patch)
treef2730a84c336ac408af4fc2a9da795daf6c5234b /ring.c
parentImplement client reading from ring buffer (diff)
downloadpounce-243a5f930dce0cddd54d7d927774f7ad82b3d88e.tar.gz
pounce-243a5f930dce0cddd54d7d927774f7ad82b3d88e.zip
Use produce/consume words for ring buffer
To disambiguate clientRecv and clientRead, say clientConsume.
Diffstat (limited to '')
-rw-r--r--ring.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/ring.c b/ring.c
index d3b04f6..d66961d 100644
--- a/ring.c
+++ b/ring.c
@@ -31,7 +31,7 @@ static struct {
 	size_t write;
 } ring;
 
-void ringWrite(const char *line) {
+void ringProduce(const char *line) {
 	size_t i = ring.write++ % RingLen;
 	if (ring.lines[i]) free(ring.lines[i]);
 	ring.times[i] = time(NULL);
@@ -45,7 +45,7 @@ static struct {
 	size_t cap, len;
 } read;
 
-size_t ringReader(const char *name) {
+size_t ringConsumer(const char *name) {
 	for (size_t i = 0; i < read.len; ++i) {
 		if (!strcmp(read.names[i], name)) return i;
 	}
@@ -64,18 +64,18 @@ size_t ringReader(const char *name) {
 	return read.len++;
 }
 
-size_t ringDiff(size_t reader) {
-	assert(reader < read.len);
-	return ring.write - read.ptrs[reader];
+size_t ringDiff(size_t consumer) {
+	assert(consumer < read.len);
+	return ring.write - read.ptrs[consumer];
 }
 
-const char *ringRead(time_t *time, size_t reader) {
-	assert(reader < read.len);
-	if (!ringDiff(reader)) return NULL;
-	if (ringDiff(reader) > RingLen) {
-		read.ptrs[reader] = ring.write - RingLen;
+const char *ringConsume(time_t *time, size_t consumer) {
+	assert(consumer < read.len);
+	if (!ringDiff(consumer)) return NULL;
+	if (ringDiff(consumer) > RingLen) {
+		read.ptrs[consumer] = ring.write - RingLen;
 	}
-	size_t i = read.ptrs[reader]++ % RingLen;
+	size_t i = read.ptrs[consumer]++ % RingLen;
 	if (time) *time = ring.times[i];
 	return ring.lines[i];
 }