tsrb.h File Reference

Thread-safe ringbuffer implementation. More...

Detailed Description

This ringbuffer implementation can be used without locking if there's only one producer and one consumer.

Buffer size must be a power of two!
Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file tsrb.h.

#include <assert.h>
#include <stddef.h>
+ Include dependency graph for tsrb.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tsrb
 thread-safe ringbuffer struct More...


#define TSRB_INIT(BUF)   { (BUF), sizeof (BUF), 0, 0 }
 Static initializer.


typedef struct tsrb tsrb_t
 thread-safe ringbuffer struct


static void tsrb_init (tsrb_t *rb, char *buffer, unsigned bufsize)
 Initialize a tsrb. More...
static int tsrb_empty (const tsrb_t *rb)
 Test if the tsrb is empty. More...
static unsigned int tsrb_avail (const tsrb_t *rb)
 Get number of bytes available for reading. More...
static int tsrb_full (const tsrb_t *rb)
 Test if the tsrb is full. More...
static unsigned int tsrb_free (const tsrb_t *rb)
 Get free space in ringbuffer. More...
int tsrb_get_one (tsrb_t *rb)
 Get a byte from ringbuffer. More...
int tsrb_get (tsrb_t *rb, char *dst, size_t n)
 Get bytes from ringbuffer. More...
int tsrb_add_one (tsrb_t *rb, char c)
 Add a byte to ringbuffer. More...
int tsrb_add (tsrb_t *rb, const char *src, size_t n)
 Add bytes to ringbuffer. More...