generic circular buffer implementation in C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
circbuf/README.md

45 lines
898 B

9 years ago
Circular byte buffer
====================
8 years ago
This is a circular buffer implementation, useful mainly for embedded systems (buffer for UART RX/TX queues etc).
It should be reliable with producent / consumer threads (no race conditions, as no length variable is used).
9 years ago
Usage
-----
```c
#include <stdint.h>
8 years ago
#include "circbuf.h"
9 years ago
8 years ago
circbuf_t cb; // buffer instance
9 years ago
void main()
{
8 years ago
char c;
cbuf_init(&cb, 32); // init the buffer
9 years ago
// now it's ready for use!
8 years ago
cbuf_write(&cb, 'A');
if (cbuf_read(&cb, &c)) {
printf("%c", c);
}
cbuf_deinit(&cb); // free the backing array (in embedded system you don't usually need to, allocate once and keep it)
9 years ago
}
```
8 years ago
Most functions return a success flag (true - success), so make sure to check the return values.
9 years ago
8 years ago
False is returned on buffer overflow / underflow. See the header file for details.
9 years ago
License
-------
8 years ago
I don't care, public domain (I guess).