*/
#include <common/dynamic-buffer.h>
-#include <common/macros.h>
#include <common/utils.h>
#include <assert.h>
+/*
+ * Round to (upper) power of two, val is returned if it already is a power of
+ * two.
+ */
static
size_t round_to_power_of_2(size_t val)
{
return rounded;
}
+LTTNG_HIDDEN
void lttng_dynamic_buffer_init(struct lttng_dynamic_buffer *buffer)
{
assert(buffer);
memset(buffer, 0, sizeof(*buffer));
}
+LTTNG_HIDDEN
int lttng_dynamic_buffer_append(struct lttng_dynamic_buffer *buffer,
const void *buf, size_t len)
{
goto end;
}
- assert(buffer->capacity >= buffer->size);
- if (buffer->capacity < (len + buffer->size)) {
+ assert(buffer->_capacity >= buffer->size);
+ if (buffer->_capacity < (len + buffer->size)) {
ret = lttng_dynamic_buffer_set_capacity(buffer,
- buffer->capacity +
- (len - (buffer->capacity - buffer->size)));
+ buffer->_capacity +
+ (len - (buffer->_capacity - buffer->size)));
if (ret) {
goto end;
}
return ret;
}
+LTTNG_HIDDEN
int lttng_dynamic_buffer_append_buffer(struct lttng_dynamic_buffer *dst_buffer,
struct lttng_dynamic_buffer *src_buffer)
{
return ret;
}
+LTTNG_HIDDEN
int lttng_dynamic_buffer_set_size(struct lttng_dynamic_buffer *buffer,
size_t new_size)
{
goto end;
}
- if (new_size > buffer->capacity) {
+ if (new_size > buffer->_capacity) {
size_t original_size = buffer->size;
- size_t original_capacity = buffer->capacity;
+ size_t original_capacity = buffer->_capacity;
ret = lttng_dynamic_buffer_set_capacity(buffer, new_size);
if (ret) {
return ret;
}
+LTTNG_HIDDEN
int lttng_dynamic_buffer_set_capacity(struct lttng_dynamic_buffer *buffer,
size_t demanded_capacity)
{
goto end;
}
- if (new_capacity == buffer->capacity) {
+ if (new_capacity == buffer->_capacity) {
goto end;
}
goto end;
}
buffer->data = new_buf;
- buffer->capacity = new_capacity;
+ buffer->_capacity = new_capacity;
end:
return ret;
}
/* Release any memory used by the dynamic buffer. */
+LTTNG_HIDDEN
void lttng_dynamic_buffer_reset(struct lttng_dynamic_buffer *buffer)
{
if (!buffer) {
return;
}
buffer->size = 0;
- buffer->capacity = 0;
+ buffer->_capacity = 0;
free(buffer->data);
}