#include "util.h"
#include "array.h"
Go to the source code of this file.
Data Structures | |
| struct | Circbuf_t |
| Structure for keeping a generic circular buffer. More... | |
Defines | |
| #define | Circbuf_Init(type, N) Circbuf_DoAlloc( sizeof( type ), ( (N) + 1) ) |
| Initialize the buffer. | |
| #define | Circbuf_Insert(type, cb, datum) |
| Insert an entry into the buffer; return 1 on succ completion, 0 otherwise. | |
| #define | Circbuf_Delete(type, cb) |
| Code to delete an entry from a circular buffer; value returned is deleted item. | |
Typedefs | |
| typedef Circbuf_t | Circbuf_t |
Enumerations | |
| enum | CircbufErrorType_t { CircbufDeleteEmpty_c, CircbufInsertFull_c } |
| Types of errors when manipulating a Circbuf. More... | |
Functions | |
| Circbuf_t * | Circbuf_DoAlloc (int, int) |
| Allocate a circular buffer with entries of size entrySize. | |
| int | Circbuf_Num (Circbuf_t *) |
| Number of entries. | |
Definition in file circbuf.h.
| #define Circbuf_Delete | ( | type, | |||
| cb | ) |
Value:
( !Circbuf_IsEmpty( cb ) ) ? \
( ( cb->numEntries-- ) , \
( cb->head = ( Circbuf_Mod( ( cb->head + 1 ) , cb->N ) ) ), \
( array_fetch( type, cb->entries, Circbuf_Mod( ( cb->head - 1 ) , cb->N ) ) ) ) \
: \
( ( fprintf( stderr, "CircbufDeleteEmpty_c\n" ), assert(0), ( array_fetch( type, cb->entries, cb->N + 1 ) ) ) )
For some reason we cannot just use fail (maybe because it's a macro?) so we print the error, assert 0, and do an array fetch (which will also fail in case we used -O4, removed the assert, and the type of the comma operator works out ok (fetching type)
| #define Circbuf_Init | ( | type, | |||
| N | ) | Circbuf_DoAlloc( sizeof( type ), ( (N) + 1) ) |
| #define Circbuf_Insert | ( | type, | |||
| cb, | |||||
| datum | ) |
Value:
( assert( !Circbuf_IsFull( cb ) ), \
( array_insert( type, cb->entries, cb->tail, datum ) ), \
( cb->numEntries++ ), \
( cb->tail = Circbuf_Mod( ( cb->tail + 1 ), cb->N ) ) )
Circbuf_IsFull( cb ) ? \ ( fail( "CircbufInsertFull_c" ) ) : \ ( ( array_insert( type, cb->entries, cb->tail, datum ) ), \ ( cb->numEntries++ ), \ ( cb->tail = Circbuf_Mod( ( cb->tail + 1 ), cb->N ) ) )
| enum CircbufErrorType_t |
| Circbuf_t* Circbuf_DoAlloc | ( | int | , | |
| int | ||||
| ) |