From 53a351b66eab09fd9cff272300b34d9dc286d6ed Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sun, 16 Feb 2020 10:17:12 -0700 Subject: [PATCH] libsysprof-capture: add clear/reset API for mapped ring buffer --- src/libsysprof-capture/mapped-ring-buffer.c | 22 +++++++++++++++++++++ src/libsysprof-capture/mapped-ring-buffer.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/libsysprof-capture/mapped-ring-buffer.c b/src/libsysprof-capture/mapped-ring-buffer.c index b051a54d..11499b64 100644 --- a/src/libsysprof-capture/mapped-ring-buffer.c +++ b/src/libsysprof-capture/mapped-ring-buffer.c @@ -621,3 +621,25 @@ mapped_ring_buffer_create_source (MappedRingBuffer *self, { return mapped_ring_buffer_create_source_full (self, source_func, user_data, NULL); } + +/** + * mapped_ring_buffer_clear: + * @self: a #MappedRingBuffer + * + * Resets the head and tail positions back to 0. + * + * This function is only safe to call when you control both the reader + * and writer sides with mapped_ring_buffer_new_readwrite(), or are in + * control of when each side reads or writes. + */ +void +mapped_ring_buffer_clear (MappedRingBuffer *self) +{ + MappedRingHeader *header; + + g_return_if_fail (self != NULL); + + header = get_header (self); + header->head = 0; + header->tail = 0; +} diff --git a/src/libsysprof-capture/mapped-ring-buffer.h b/src/libsysprof-capture/mapped-ring-buffer.h index 45387c35..4eee6953 100644 --- a/src/libsysprof-capture/mapped-ring-buffer.h +++ b/src/libsysprof-capture/mapped-ring-buffer.h @@ -66,6 +66,8 @@ MappedRingBuffer *mapped_ring_buffer_ref (MappedRingBuffer G_GNUC_INTERNAL void mapped_ring_buffer_unref (MappedRingBuffer *self); G_GNUC_INTERNAL +void mapped_ring_buffer_clear (MappedRingBuffer *self); +G_GNUC_INTERNAL gpointer mapped_ring_buffer_allocate (MappedRingBuffer *self, gsize length); G_GNUC_INTERNAL