Fix: don't flush-final for offset 0 if reader is on sub-buffer
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 27 Feb 2013 21:39:30 +0000 (16:39 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 27 Feb 2013 21:41:44 +0000 (16:41 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
libringbuffer/ring_buffer_frontend.c

index 7762da7291ae5d1f215ee0c47039bd8c84f78d28..6719626c2d5672d1f4b32b1800e79f3fdd98f672 100644 (file)
@@ -1233,6 +1233,19 @@ int lib_ring_buffer_try_switch_slow(enum switch_mode mode,
         */
        if (mode == SWITCH_FLUSH || off > 0) {
                if (caa_unlikely(off == 0)) {
+                       /*
+                        * A final flush that encounters an empty
+                        * sub-buffer cannot switch buffer if a
+                        * reader is located within this sub-buffer.
+                        * Anyway, the purpose of final flushing of a
+                        * sub-buffer at offset 0 is to handle the case
+                        * of entirely empty stream.
+                        */
+                       if (caa_unlikely(subbuf_trunc(offsets->begin, chan)
+                                        - subbuf_trunc((unsigned long)
+                                            uatomic_read(&buf->consumed), chan)
+                                       >= chan->backend.buf_size))
+                               return -1;
                        /*
                         * The client does not save any header information.
                         * Don't switch empty subbuffer on finalize, because it
This page took 0.035879 seconds and 4 git commands to generate.