Program Listing for File multififo.h

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

#pragma once

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

/*******************************************************************************
 * Structure Definitions
 ******************************************************************************/
struct multififo_params {
  dptr_t *elements;

  dptr_t* meta;

  size_t elt_size;

  size_t max_elts;

  size_t n_children;

  size_t* children;

  uint32_t flags;
};

struct multififo_children_mgmt {
  struct fifo* fifos;

  dptr_t* elements;

  size_t count;
};

struct multififo {
  struct fifo root;

  uint8_t front_refmask;

  bool locked;

  struct multififo_children_mgmt children;

  uint32_t flags;
};

BEGIN_C_DECLS

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

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

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

static inline size_t multififo_islocked(const struct multififo* const fifo) {
    RCSW_FPC_NV(0, NULL != fifo);
    return fifo->locked;
}

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

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

static inline size_t multififo_meta_space(size_t elt_size, size_t n_children) {
  /*
   * Each child FIFO needs a handle + 1 root FIFO element worth of space to
   * store its elements.
   */
  return (sizeof(struct fifo) + elt_size) * n_children;
}

RCSW_API struct multififo *multififo_init(struct multififo *fifo_in,
                                            const struct multififo_params * params) RCSW_WUR;

RCSW_API void multififo_destroy(struct multififo *fifo);

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

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

RCSW_API status_t multififo_remove(struct multififo * fifo, void * e);

RCSW_API status_t multififo_clear(struct multififo * fifo);

END_C_DECLS