#include "sst_internal.h" #ifdef CONFIG_SST_BOUNDS #define OFFSET (4 * BOUNDEDBUFFER_SIZE) #else #define OFFSET 0 #endif void init_bbuffer(struct boundedbuffer *buffer) { buffer->next_in = 0; buffer->next_out = 0; buffer->size = BOUNDEDBUFFER_SIZE; } int is_full(struct boundedbuffer *buffer) { return (buffer->next_in + 1) % buffer->size == buffer->next_out; } int is_empty(struct boundedbuffer *buffer) { return buffer->next_out == buffer->next_in; } int produce(struct boundedbuffer *buffer, BOUNDEDBUFFER_STORAGE_TYPE data) { if (is_full(buffer)) { return -1; } buffer->data[buffer->next_in + OFFSET] = data; buffer->next_in = (buffer->next_in + 1) % buffer->size; return 0; } int consume(struct boundedbuffer *buffer, BOUNDEDBUFFER_STORAGE_TYPE *ret) { if (is_empty(buffer)) { return -1; } *ret = buffer->data[buffer->next_out + OFFSET]; buffer->next_out = (buffer->next_out + 1) % buffer->size; return 0; }