[sysprof] libsysprof-capture: update ring position while walking



commit c74c02a2d95d6f59c97a205d250e20b2a36b0044
Author: Christian Hergert <chergert redhat com>
Date:   Sat Feb 15 21:55:08 2020 -0700

    libsysprof-capture: update ring position while walking
    
    This ensures that the producer can produce as soon as the reader has moved
    past that data. Now that the callback has a mutable consumption value, they
    can read the whole data in one shot anyway.

 src/libsysprof-capture/mapped-ring-buffer.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)
---
diff --git a/src/libsysprof-capture/mapped-ring-buffer.c b/src/libsysprof-capture/mapped-ring-buffer.c
index 0fc0d3d..8900beb 100644
--- a/src/libsysprof-capture/mapped-ring-buffer.c
+++ b/src/libsysprof-capture/mapped-ring-buffer.c
@@ -462,7 +462,6 @@ mapped_ring_buffer_drain (MappedRingBuffer         *self,
   MappedRingHeader *header;
   gsize headpos;
   gsize tailpos;
-  gboolean ret = FALSE;
 
   g_return_val_if_fail (self != NULL, FALSE);
   g_return_val_if_fail (self->mode == MODE_READER, FALSE);
@@ -492,26 +491,20 @@ mapped_ring_buffer_drain (MappedRingBuffer         *self,
       gsize len = tailpos - headpos;
 
       if (!callback (data, &len, user_data))
-        goto short_circuit;
+        return FALSE;
 
       if (len > (tailpos - headpos))
-        goto short_circuit;
+        return FALSE;
 
       headpos += len;
-    }
-
-  ret = TRUE;
-
-short_circuit:
-
-  if (headpos >= self->body_size)
-    headpos -= self->body_size;
 
-  g_assert (headpos < self->body_size);
-
-  g_atomic_int_set (&header->head, headpos);
+      if (headpos >= self->body_size)
+        g_atomic_int_set (&header->head, headpos - self->body_size);
+      else
+        g_atomic_int_set (&header->head, headpos);
+    }
 
-  return ret;
+  return TRUE;
 }
 
 typedef struct _MappedRingSource
@@ -598,8 +591,6 @@ mapped_ring_buffer_create_source_full (MappedRingBuffer         *self,
   g_return_val_if_fail (self != NULL, 0);
   g_return_val_if_fail (source_func != NULL, 0);
 
-  /* TODO: Can we use G_IO_IN with the memfd? */
-
   source = (MappedRingSource *)g_source_new (&mapped_ring_source_funcs, sizeof (MappedRingSource));
   source->self = mapped_ring_buffer_ref (self);
   g_source_set_callback ((GSource *)source, (GSourceFunc)source_func, user_data, destroy);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]