lib ring buffer iterator: introduce lib_ring_buffer_put_current_record
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 4 Feb 2020 20:44:55 +0000 (15:44 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 18 Nov 2020 18:02:37 +0000 (13:02 -0500)
Ensure that the current subbuffer is put after client code has read the
payload of the current record.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Id2173ea67213f7ef8e7395b49c5aa8fff0aefffc

include/ringbuffer/iterator.h
src/lib/ringbuffer/ring_buffer_iterator.c

index a006ed00e1bb34b66da9f7552a2f8435605a4702..a9879903503dbb44d118bb6de9473c6123676d34 100644 (file)
 extern ssize_t lib_ring_buffer_get_next_record(struct channel *chan,
                                               struct lib_ring_buffer *buf);
 
+/*
+ * Ensure that the current subbuffer is put after client code has read the
+ * payload of the current record. Has an effect when the end of subbuffer is
+ * reached. It is not required if get_next_record is called successively.
+ * However, it should be invoked before returning data to user-space to ensure
+ * that the get/put subbuffer state is quiescent.
+ */
+extern void lib_ring_buffer_put_current_record(struct lib_ring_buffer *buf);
+
 /*
  * channel_get_next_record advances the buffer read position to the next record.
  * It returns either the size of the next record, -EAGAIN if there is currently
index a136a8faa5658ed316c5336eafe162cd0fc63f66..da19d28053dca4bb7c700d7c390b04ab5405a331 100644 (file)
@@ -105,6 +105,24 @@ restart:
 }
 EXPORT_SYMBOL_GPL(lib_ring_buffer_get_next_record);
 
+void lib_ring_buffer_put_current_record(struct lib_ring_buffer *buf)
+{
+       struct lib_ring_buffer_iter *iter;
+
+       if (!buf)
+               return;
+       iter = &buf->iter;
+       if (iter->state != ITER_NEXT_RECORD)
+               return;
+       iter->read_offset += iter->payload_len;
+       iter->state = ITER_TEST_RECORD;
+       if (iter->read_offset - iter->consumed >= iter->data_size) {
+               lib_ring_buffer_put_next_subbuf(buf);
+               iter->state = ITER_GET_SUBBUF;
+       }
+}
+EXPORT_SYMBOL_GPL(lib_ring_buffer_put_current_record);
+
 static int buf_is_higher(void *a, void *b)
 {
        struct lib_ring_buffer *bufa = a;
@@ -696,12 +714,14 @@ skip_get_next:
                        return -EFAULT;
                }
                read_count += copy_len;
-       };
-       return read_count;
+       }
+       goto put_record;
 
 nodata:
        *ppos = 0;
        chan->iter.len_left = 0;
+put_record:
+       lib_ring_buffer_put_current_record(buf);
        return read_count;
 }
 
This page took 0.02659 seconds and 4 git commands to generate.