30 lines
1002 B
C
30 lines
1002 B
C
|
#ifndef __BOUNDEDBUFFER_H__
|
||
|
#define __BOUNDEDBUFFER_H__
|
||
|
/*
|
||
|
* For some reasons, our ring buffer (aka BSB ring buffer)
|
||
|
* can only hold size - 1 elements.
|
||
|
* If we want to store BOUNDEDBUFFER_SIZE elements, as desired,
|
||
|
* the buffer must be one element larger.
|
||
|
* Hence, BOUNDEDBUFFER_SIZE_REAL is used for allocating the actual buffer
|
||
|
* and used for the size member.
|
||
|
*/
|
||
|
#ifndef BOUNDEDBUFFER_SIZE
|
||
|
#error Buffer size not defined!
|
||
|
#endif
|
||
|
#define BOUNDEDBUFFER_SIZE_REAL (BOUNDEDBUFFER_SIZE + 1)
|
||
|
#define BOUNDEDBUFFER_SIZE_VIRT (BOUNDEDBUFFER_SIZE_REAL - 1)
|
||
|
|
||
|
struct boundedbuffer {
|
||
|
int next_in;
|
||
|
int next_out;
|
||
|
int size;
|
||
|
BOUNDEDBUFFER_STORAGE_TYPE data[BOUNDEDBUFFER_SIZE_REAL];
|
||
|
};
|
||
|
|
||
|
void init_bbuffer(struct boundedbuffer *buffer);
|
||
|
int is_full(struct boundedbuffer *buffer);
|
||
|
int is_empty(struct boundedbuffer *buffer);
|
||
|
int produce(struct boundedbuffer *buffer, BOUNDEDBUFFER_STORAGE_TYPE data);
|
||
|
int consume(struct boundedbuffer *buffer, BOUNDEDBUFFER_STORAGE_TYPE *ret);
|
||
|
#endif // __BOUNDEDBUFFER_H__
|