strrb.c File Reference
General-purpose utility functions

Ringbuffer implementation, tailored for logging. More...

`#include <stdio.h>`
`#include <string.h>`
`#include <osmocom/core/strrb.h>`
`#include <osmocom/core/talloc.h>`

## Functions

struct osmo_strrb * | osmo_strrb_create (TALLOC_CTX *ctx, size_t rb_size)
| Create an empty, initialized osmo_strrb. More...
bool | osmo_strrb_is_empty (const struct osmo_strrb *rb)
| Check if an osmo_strrb is empty. More...
const char * | osmo_strrb_get_nth (const struct osmo_strrb *rb, unsigned int string_index)
| Return a pointer to the Nth string in the osmo_strrb. More...
bool | _osmo_strrb_is_bufindex_valid (const struct osmo_strrb *rb, unsigned int bufi)
size_t | osmo_strrb_elements (const struct osmo_strrb *rb)
| Count the number of log messages in an osmo_strrb. More...
int | osmo_strrb_add (struct osmo_strrb *rb, const char *data)
| Add a string to the osmo_strrb. More...

## Detailed Description

Ringbuffer implementation, tailored for logging.

This is a lossy ringbuffer. It keeps up to N of the newest messages, overwriting the oldest as newer ones come in.

Ringbuffer assumptions, invarients, and notes:

- start is the index of the first used index slot in the ring buffer.
- end is the index of the next index slot in the ring buffer.
- start == end => buffer is empty
- Consequence: the buffer can hold at most size - 1 messages (if this were not the case, full and empty buffers would be indistinguishable given the conventions in this implementation).
- Whenever the ringbuffer is full, start is advanced. The second oldest message becomes unreachable by valid indexes (end is not a valid index) and the oldest message is overwritten (if there was a message there, which is the case unless this is the first time the ringbuffer becomes full).