summary refs log tree commit diff
path: root/ring.c
diff options
context:
space:
mode:
Diffstat (limited to 'ring.c')
-rw-r--r--ring.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ring.c b/ring.c
index 912d0d3..409fcd4 100644
--- a/ring.c
+++ b/ring.c
@@ -70,17 +70,23 @@ size_t ringDiff(size_t consumer) {
 	return ring.write - read.ptrs[consumer];
 }
 
-const char *ringConsume(time_t *time, size_t consumer) {
+const char *ringPeek(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[consumer]++ % RingLen;
+	size_t i = read.ptrs[consumer] % RingLen;
 	if (time) *time = ring.times[i];
 	return ring.lines[i];
 }
 
+const char *ringConsume(time_t *time, size_t consumer) {
+	const char *line = ringPeek(time, consumer);
+	read.ptrs[consumer]++;
+	return line;
+}
+
 void ringInfo(void) {
 	fprintf(stderr, "producer: %zu\n", ring.write);
 	for (size_t i = 0; i < read.len; ++i) {