Thread-safe ringbuffer implementation.
More...
Thread-safe ringbuffer implementation.
- Attention
- Buffer size must be a power of two!
|
file | tsrb.h |
| Thread-safe ringbuffer interface definition.
|
|
|
#define | TSRB_INIT(BUF) { (BUF), sizeof (BUF), 0, 0 } |
| Static initializer.
|
|
|
typedef struct tsrb | tsrb_t |
| thread-safe ringbuffer struct
|
|
◆ tsrb_add()
int tsrb_add |
( |
tsrb_t * |
rb, |
|
|
const uint8_t * |
src, |
|
|
size_t |
n |
|
) |
| |
Add bytes to ringbuffer.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
[in] | src | buffer to read from |
[in] | n | max number of bytes to read from src |
- Returns
- nr of bytes read from
src
◆ tsrb_add_one()
int tsrb_add_one |
( |
tsrb_t * |
rb, |
|
|
uint8_t |
c |
|
) |
| |
Add a byte to ringbuffer.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
[in] | c | Character to add to ringbuffer |
- Returns
- 0 on success
-
-1 if no space available
◆ tsrb_avail()
static unsigned int tsrb_avail |
( |
const tsrb_t * |
rb | ) |
|
|
inlinestatic |
Get number of bytes available for reading.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
- Returns
- nr of available bytes
Definition at line 90 of file tsrb.h.
◆ tsrb_drop()
int tsrb_drop |
( |
tsrb_t * |
rb, |
|
|
size_t |
n |
|
) |
| |
Drop bytes from ringbuffer.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
[in] | n | max number of bytes to drop |
- Returns
- nr of bytes dropped
◆ tsrb_empty()
static int tsrb_empty |
( |
const tsrb_t * |
rb | ) |
|
|
inlinestatic |
Test if the tsrb is empty.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
- Returns
- 0 if not empty
-
1 otherwise
Definition at line 76 of file tsrb.h.
◆ tsrb_free()
static unsigned int tsrb_free |
( |
const tsrb_t * |
rb | ) |
|
|
inlinestatic |
Get free space in ringbuffer.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
- Returns
- nr of available bytes
Definition at line 117 of file tsrb.h.
◆ tsrb_full()
static int tsrb_full |
( |
const tsrb_t * |
rb | ) |
|
|
inlinestatic |
Test if the tsrb is full.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
- Returns
- 0 if not full
-
1 otherwise
Definition at line 104 of file tsrb.h.
◆ tsrb_get()
int tsrb_get |
( |
tsrb_t * |
rb, |
|
|
uint8_t * |
dst, |
|
|
size_t |
n |
|
) |
| |
Get bytes from ringbuffer.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
[out] | dst | buffer to write to |
[in] | n | max number of bytes to write to dst |
- Returns
- nr of bytes written to
dst
◆ tsrb_get_one()
int tsrb_get_one |
( |
tsrb_t * |
rb | ) |
|
Get a byte from ringbuffer.
- Parameters
-
[in] | rb | Ringbuffer to operate on |
- Returns
- >=0 byte that has been read
-
-1 if no byte available
◆ tsrb_init()
static void tsrb_init |
( |
tsrb_t * |
rb, |
|
|
uint8_t * |
buffer, |
|
|
unsigned |
bufsize |
|
) |
| |
|
inlinestatic |
Initialize a tsrb.
- Parameters
-
[out] | rb | Datum to initialize. |
[in] | buffer | Buffer to use by tsrb. |
[in] | bufsize | sizeof (buffer) , must be power of 2. |
Definition at line 57 of file tsrb.h.