Program Listing for File rawfifo.h
↰ Return to documentation for file (rcsw/ds/rawfifo.h
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include "rcsw/rcsw.h"
#include "rcsw/common/fpc.h"
/*******************************************************************************
* Type Definitions
******************************************************************************/
struct rawfifo {
dptr_t *elements;
size_t to_i;
size_t from_i;
size_t max_elts;
size_t elt_size;
};
/*******************************************************************************
* API Functions
******************************************************************************/
BEGIN_C_DECLS
static inline status_t rawfifo_clear(struct rawfifo *const fifo) {
RCSW_FPC_NV(ERROR, NULL != fifo);
fifo->to_i = fifo->from_i;
return OK;
}
static inline size_t rawfifo_size(const struct rawfifo *const fifo) {
RCSW_FPC_NV(0, NULL != fifo);
if (fifo->to_i >= fifo->from_i) {
return fifo->to_i - fifo->from_i;
}
return (fifo->to_i) + (fifo->max_elts - fifo->from_i);
} /* rawfifo_size() */
static inline size_t rawfifo_n_free(const struct rawfifo *const fifo) {
RCSW_FPC_NV(0, NULL != fifo);
/* One elt must be wasted to make n_elts determination unambiguous */
return fifo->max_elts - rawfifo_size(fifo) - 1;
}
RCSW_API status_t rawfifo_init(struct rawfifo * fifo,
void* buf,
size_t max_elts,
size_t elt_size);
RCSW_API size_t rawfifo_deq(struct rawfifo * fifo, void * e, size_t n_elts);
RCSW_API size_t rawfifo_enq(struct rawfifo * fifo,
const void * elts,
size_t n_elts);
END_C_DECLS