forked from pixelmatix/SmartMatrix
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCircularBuffer.h
32 lines (21 loc) · 841 Bytes
/
CircularBuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef _CIRCULARBUFFER_H_
#define _CIRCULARBUFFER_H_
// TODO: Consider INLINE for several functions - many small, only used in one place, in frequently used code
/* Circular buffer object */
typedef struct {
int size; /* maximum number of elements */
int start; /* index of oldest element */
int count; /* new */
} CircularBuffer;
void cbInit(CircularBuffer *cb, int size);
int cbIsFull(CircularBuffer *cb);
int cbIsEmpty(CircularBuffer *cb);
// returns index of next element to write
int cbGetNextWrite(CircularBuffer *cb);
// mark next element as written
void cbWrite(CircularBuffer *cb);
// returns index of next element to read
int cbGetNextRead(CircularBuffer *cb);
// marks next element as read
void cbRead(CircularBuffer *cb);
#endif // _CIRCULARBUFFER_H_