Program Listing for File swbus.h

Return to documentation for file (rcsw/swbus/swbus.h)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcsw/multithread/cvm.h"
#include "rcsw/multithread/mutex.h"
#include "rcsw/multithread/pcqueue.h"
#include "rcsw/rcsw.h"
#include "rcsw/multithread/mpool.h"
#include "rcsw/ds/rbuffer.h"
#include "rcsw/multithread/rdwrlock.h"

/*******************************************************************************
 * Constant Definitions
 ******************************************************************************/
/* Just to make things easy */
#define RCSW_SWBUS_MAX_NAMELEN 32

#define RCSW_SWBUS_NOALLOC_POOLS (RCSW_NOALLOC_DATA | RCSW_NOALLOC_META)

#define RCSW_SWBUS_ASYNC (1 << RCSW_MODFLAGS_START )

/*******************************************************************************
 * Structure Definitions
 ******************************************************************************/
struct swbus_params {
  struct mpool_params* pools;

  size_t max_pools;

  size_t max_rxqs;

  size_t max_subs;

  uint32_t flags;

  char name[RCSW_SWBUS_MAX_NAMELEN];
};

struct swbus_rxq_ent {
  dptr_t* data;

  size_t pkt_size;

  uint32_t pid;

  struct mpool *bp;
};

struct swbus_rsrvn {
  dptr_t* data;

  size_t pkt_size;

  struct mpool *bp;
};

struct swbus_sub {
  uint32_t pid;

  struct pcqueue *subscriber;
};

struct swbus {
  size_t n_pools;

  size_t n_rxqs;

  size_t max_rxqs;

  size_t max_subs;

  struct mutex mutex;

  uint32_t flags;

  struct mpool *pools;

  struct pcqueue *rxqs;

  struct llist *subscribers;

  struct rdwrlock syncl;

  char name[RCSW_SWBUS_MAX_NAMELEN];
};

/*******************************************************************************
 * API Functions
 ******************************************************************************/
BEGIN_C_DECLS

RCSW_API struct swbus_rxq_ent* swbus_rxq_front(struct pcqueue *const queue);

RCSW_API struct swbus *swbus_init(struct swbus *swb_in,
                                  const struct swbus_params * params) RCSW_WUR;

RCSW_API void swbus_destroy(struct swbus *swb);

RCSW_API struct pcqueue *swbus_rxq_init(struct swbus * swb,
                                        void * buf_p,
                                        uint32_t n_entries) RCSW_WUR;

RCSW_API status_t swbus_subscribe(struct swbus * swb,
                                  struct pcqueue * queue,
                                  uint32_t pid);

RCSW_API status_t swbus_unsubscribe(struct swbus * swb,
                                    struct pcqueue * queue,
                                    uint32_t pid);

RCSW_API status_t swbus_publish(struct swbus * swb,
                                uint32_t pid,
                                size_t pkt_size,
                                const void* pkt);

RCSW_API status_t swbus_publish_reserve(struct swbus* swb,
                                        struct swbus_rsrvn* res,
                                        size_t pkt_size);
RCSW_API status_t swbus_publish_release(struct swbus* swb,
                                        uint32_t pid,
                                        struct swbus_rsrvn* res,
                                        size_t pkt_size);

RCSW_API struct swbus_rxq_ent* swbus_rxq_wait(struct swbus* swb,
                                              struct pcqueue * queue) RCSW_WUR;

RCSW_API struct swbus_rxq_ent* swbus_rxq_timedwait(struct swbus* swb,
                                                   struct pcqueue * queue,
                                                   struct timespec * to) RCSW_WUR;

RCSW_API status_t swbus_rxq_pop_front(struct pcqueue* queue,
                                      struct swbus_rxq_ent * ent);

END_C_DECLS