libsysprof-capture: write final frame

This frame type can be used to communicate with the peer over the mapped
ring buffer to denote that writing is finished and it can free any
resources for the mapping.
This commit is contained in:
Christian Hergert
2020-02-15 20:49:27 -07:00
parent e3ed30eb48
commit c36420d716

View File

@ -184,6 +184,24 @@ request_writer (void)
return g_steal_pointer (&buffer);
}
static void
write_final_frame (MappedRingBuffer *ring)
{
SysprofCaptureFrame *fr;
g_assert (ring != NULL);
if ((fr = mapped_ring_buffer_allocate (ring, sizeof *fr)))
{
fr->len = sizeof *fr; /* aligned */
fr->type = 0xFF; /* Invalid */
fr->cpu = -1;
fr->pid = -1;
fr->time = SYSPROF_CAPTURE_CURRENT_TIME;
mapped_ring_buffer_advance (ring, fr->len);
}
}
static void
sysprof_collector_free (gpointer data)
{
@ -191,7 +209,12 @@ sysprof_collector_free (gpointer data)
if (collector != NULL && collector != COLLECTOR_MAGIC_CREATING)
{
g_clear_pointer (&collector->buffer, mapped_ring_buffer_unref);
if (collector->buffer != NULL)
{
write_final_frame (collector->buffer);
g_clear_pointer (&collector->buffer, mapped_ring_buffer_unref);
}
g_free (collector);
}
}