mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 15:10:53 +00:00
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.
This commit is contained in:
@ -462,7 +462,6 @@ mapped_ring_buffer_drain (MappedRingBuffer *self,
|
|||||||
MappedRingHeader *header;
|
MappedRingHeader *header;
|
||||||
gsize headpos;
|
gsize headpos;
|
||||||
gsize tailpos;
|
gsize tailpos;
|
||||||
gboolean ret = FALSE;
|
|
||||||
|
|
||||||
g_return_val_if_fail (self != NULL, FALSE);
|
g_return_val_if_fail (self != NULL, FALSE);
|
||||||
g_return_val_if_fail (self->mode == MODE_READER, 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;
|
gsize len = tailpos - headpos;
|
||||||
|
|
||||||
if (!callback (data, &len, user_data))
|
if (!callback (data, &len, user_data))
|
||||||
goto short_circuit;
|
return FALSE;
|
||||||
|
|
||||||
if (len > (tailpos - headpos))
|
if (len > (tailpos - headpos))
|
||||||
goto short_circuit;
|
return FALSE;
|
||||||
|
|
||||||
headpos += len;
|
headpos += len;
|
||||||
|
|
||||||
|
if (headpos >= self->body_size)
|
||||||
|
g_atomic_int_set (&header->head, headpos - self->body_size);
|
||||||
|
else
|
||||||
|
g_atomic_int_set (&header->head, headpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return 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);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _MappedRingSource
|
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 (self != NULL, 0);
|
||||||
g_return_val_if_fail (source_func != 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 = (MappedRingSource *)g_source_new (&mapped_ring_source_funcs, sizeof (MappedRingSource));
|
||||||
source->self = mapped_ring_buffer_ref (self);
|
source->self = mapped_ring_buffer_ref (self);
|
||||||
g_source_set_callback ((GSource *)source, (GSourceFunc)source_func, user_data, destroy);
|
g_source_set_callback ((GSource *)source, (GSourceFunc)source_func, user_data, destroy);
|
||||||
|
|||||||
Reference in New Issue
Block a user