Program Listing for File fifo.h

Return to documentation for file (rcsw/ds/fifo.h)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcsw/ds/rbuffer.h"
#include "rcsw/common/fpc.h"

/*******************************************************************************
 * Structure Definitions
 ******************************************************************************/
struct fifo_params {
  void (*printe)(const void *e);

  dptr_t *elements;

  size_t elt_size;

  size_t max_elts;

  uint32_t flags;
};

struct fifo {
  struct rbuffer rb;

  size_t elt_size;

  uint32_t flags;
};

BEGIN_C_DECLS

/*******************************************************************************
 * API Functions
 ******************************************************************************/
static inline bool_t fifo_isfull(const struct fifo* const fifo) {
    RCSW_FPC_NV(false, NULL != fifo);
    return rbuffer_isfull(&fifo->rb);
}

static inline bool_t fifo_isempty(const struct fifo* const fifo) {
    RCSW_FPC_NV(false, NULL != fifo);
    return rbuffer_isempty(&fifo->rb);
}

static inline size_t fifo_size(const struct fifo* const fifo) {
    RCSW_FPC_NV(0, NULL != fifo);
    return rbuffer_size(&fifo->rb);
}

static inline size_t fifo_capacity(const struct fifo* const fifo) {
    RCSW_FPC_NV(0, NULL != fifo);
    return rbuffer_capacity(&fifo->rb);
}

static inline void* fifo_front(const struct fifo* const fifo) {
    RCSW_FPC_NV(0, NULL != fifo);
    return rbuffer_front(&fifo->rb);
}

static inline size_t fifo_element_space(size_t max_elts, size_t elt_size) {
    return rbuffer_element_space(max_elts, elt_size);
}

RCSW_API struct fifo *fifo_init(struct fifo *fifo_in,
                                const struct fifo_params * params) RCSW_WUR;

RCSW_API void fifo_destroy(struct fifo *fifo);

RCSW_API status_t fifo_add(struct fifo * fifo, const void * e);

RCSW_API status_t fifo_remove(struct fifo * fifo, void * e);

RCSW_API status_t fifo_clear(struct fifo * fifo);

RCSW_API status_t fifo_map(struct fifo * fifo, void (*f)(void *e));

RCSW_API status_t fifo_inject(struct fifo * fifo,
                     void (*f)(void *e, void *res), void *result);

RCSW_API void fifo_print(struct fifo * fifo);

END_C_DECLS