31 memset (mq, 0,
sizeof (*mq));
35 for (i = 0; i < cfg->
n_rings; i++)
78 __sync_fetch_and_add (&ring->
cursize, 1);
93 ASSERT (elt_index < ring->nitems);
94 return (ring->
data + elt_index * ring->
elsize);
121 __sync_fetch_and_sub (&ring->
cursize, 1);
139 return (dist1 < dist2);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
svm_msg_q_ring_t * rings
rings with message data
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queu.
int svm_queue_add(svm_queue_t *q, u8 *elem, int nowait)
svm_msg_q_msg_t svm_msg_q_alloc_msg(svm_msg_q_t *mq, u32 nbytes)
Allocate message buffer.
svm_queue_t * svm_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
static svm_msg_q_ring_t * svm_msg_q_get_ring(svm_msg_q_t *mq, u32 ring_index)
int svm_queue_sub(svm_queue_t *q, u8 *elem, svm_q_conditional_wait_t cond, u32 time)
svm_msg_q_t * svm_msg_q_alloc(svm_msg_q_cfg_t *cfg)
Allocate message queue.
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
int svm_msg_q_sub(svm_msg_q_t *mq, svm_msg_q_msg_t *msg, svm_q_conditional_wait_t cond, u32 time)
Consumer dequeue one message from queue.
void svm_msg_q_free(svm_msg_q_t *mq)
Free message queue.
static int svm_msq_q_msg_is_valid(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
volatile u32 cursize
current size of the ring
u32 n_rings
number of msg rings
u32 head
current head (for dequeue)
Unidirectional shared-memory multi-ring message queue.
#define vec_free(V)
Free vector's memory (no header).
svm_queue_t * q
queue for exchanging messages
u32 elt_index
index in ring
u32 ring_index
ring index, could be u8
static void clib_mem_free(void *p)
u8 * data
chunk of memory for msg data
svm_msg_q_ring_cfg_t * ring_cfgs
array of ring cfgs
u32 q_nitems
msg queue size (not rings)
void svm_msg_q_free_msg(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Free message buffer.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 elsize
size of an element
static void * clib_mem_alloc_aligned(uword size, uword align)
u32 tail
current tail (for enqueue)
#define vec_foreach(var, vec)
Vector iterator.
int consumer_pid
pid of msg consumer
#define CLIB_CACHE_LINE_BYTES
int svm_msg_q_add(svm_msg_q_t *mq, svm_msg_q_msg_t msg, int nowait)
Producer enqueue one message to queue.
static void * svm_msg_q_ring_data(svm_msg_q_ring_t *ring, u32 elt_index)
u32 nitems
max size of the ring