diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/qemu/buffer.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/include/qemu/buffer.h b/include/qemu/buffer.h index b380cec6fa..dead9b77e1 100644 --- a/include/qemu/buffer.h +++ b/include/qemu/buffer.h @@ -34,12 +34,35 @@ typedef struct Buffer Buffer; */ struct Buffer { + char *name; size_t capacity; size_t offset; + uint64_t avg_size; uint8_t *buffer; }; /** + * buffer_init: + * @buffer: the buffer object + * @name: buffer name + * + * Optionally attach a name to the buffer, to make it easier + * to identify in debug traces. + */ +void buffer_init(Buffer *buffer, const char *name, ...) + GCC_FMT_ATTR(2, 3); + +/** + * buffer_shrink: + * @buffer: the buffer object + * + * Try to shrink the buffer. Checks current buffer capacity and size + * and reduces capacity in case only a fraction of the buffer is + * actually used. + */ +void buffer_shrink(Buffer *buffer); + +/** * buffer_reserve: * @buffer: the buffer object * @len: the minimum required free space @@ -115,4 +138,24 @@ uint8_t *buffer_end(Buffer *buffer); */ gboolean buffer_empty(Buffer *buffer); +/** + * buffer_move_empty: + * @to: destination buffer object + * @from: source buffer object + * + * Moves buffer, without copying data. 'to' buffer must be empty. + * 'from' buffer is empty and zero-sized on return. + */ +void buffer_move_empty(Buffer *to, Buffer *from); + +/** + * buffer_move: + * @to: destination buffer object + * @from: source buffer object + * + * Moves buffer, copying data (unless 'to' buffer happens to be empty). + * 'from' buffer is empty and zero-sized on return. + */ +void buffer_move(Buffer *to, Buffer *from); + #endif /* QEMU_BUFFER_H__ */ |