From: Jérémie Galarneau Date: Tue, 17 Oct 2017 21:21:10 +0000 (-0400) Subject: Add lttng_dynamic_buffer_get_capacity_left util X-Git-Tag: v2.11.0-rc1~101 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=201bd4152ffcd30d3e2269d842258c885e6cc193;p=lttng-tools.git Add lttng_dynamic_buffer_get_capacity_left util Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/dynamic-buffer.c b/src/common/dynamic-buffer.c index fd39f813b..2e27afa1f 100644 --- a/src/common/dynamic-buffer.c +++ b/src/common/dynamic-buffer.c @@ -186,3 +186,13 @@ void lttng_dynamic_buffer_reset(struct lttng_dynamic_buffer *buffer) buffer->_capacity = 0; free(buffer->data); } + +LTTNG_HIDDEN +size_t lttng_dynamic_buffer_get_capacity_left( + struct lttng_dynamic_buffer *buffer) +{ + if (!buffer) { + return 0; + } + return buffer->_capacity - buffer->size; +} diff --git a/src/common/dynamic-buffer.h b/src/common/dynamic-buffer.h index d42a6a61d..cd23ccad4 100644 --- a/src/common/dynamic-buffer.h +++ b/src/common/dynamic-buffer.h @@ -94,4 +94,9 @@ int lttng_dynamic_buffer_set_capacity(struct lttng_dynamic_buffer *buffer, LTTNG_HIDDEN void lttng_dynamic_buffer_reset(struct lttng_dynamic_buffer *buffer); +/* Get the space left in the buffer before a new resize is needed. */ +LTTNG_HIDDEN +size_t lttng_dynamic_buffer_get_capacity_left( + struct lttng_dynamic_buffer *buffer); + #endif /* LTTNG_DYNAMIC_BUFFER_H */