34 ASSERT (elt_index < ring->nitems);
35 return (ring->
data + elt_index * ring->
elsize);
50 memset (mq, 0,
sizeof (*mq));
54 for (i = 0; i < cfg->
n_rings; i++)
94 __sync_fetch_and_add (&ring->
cursize, 1);
144 __sync_fetch_and_add (&ring->
cursize, 1);
174 __sync_fetch_and_sub (&ring->
cursize, 1);
192 return (dist1 < dist2);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
void svm_queue_add_raw(svm_queue_t *q, u8 *elem)
Add element to queue with mutex held.
static u8 svm_msg_q_msg_is_invalid(svm_msg_q_msg_t *msg)
Check if message is invalid.
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 queue.
static u8 svm_msg_q_ring_is_full(svm_msg_q_t *mq, u32 ring_index)
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.
volatile u32 head
current head (for dequeue)
static svm_msg_q_ring_t * svm_msg_q_ring_inline(svm_msg_q_t *mq, u32 ring_index)
svm_queue_t * svm_queue_init(int nels, int elsize, int consumer_pid, int signal_when_queue_non_empty)
int svm_msg_q_lock_and_alloc_msg_w_ring(svm_msg_q_t *mq, u32 ring_index, u8 noblock, svm_msg_q_msg_t *msg)
Lock message queue and allocate message buffer on ring.
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.
volatile u32 tail
current tail (for enqueue)
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.
svm_msg_q_ring_t * svm_msg_q_ring(svm_msg_q_t *mq, u32 ring_index)
Get message queue ring.
static int svm_msq_q_msg_is_valid(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
static void svm_msg_q_wait(svm_msg_q_t *mq)
volatile u32 cursize
current size of the ring
u32 n_rings
number of msg rings
Unidirectional shared-memory multi-ring message queue.
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
#define vec_free(V)
Free vector's memory (no header).
svm_queue_t * q
queue for exchanging messages
int svm_msg_q_add(svm_msg_q_t *mq, svm_msg_q_msg_t *msg, int nowait)
Producer enqueue one message to queue.
u32 elt_index
index in ring
static int svm_msg_q_try_lock(svm_msg_q_t *mq)
Try locking message queue.
u32 ring_index
ring index, could be u8
void svm_msg_q_add_and_unlock(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Producer enqueue one message to queue with mutex held.
static void clib_mem_free(void *p)
u8 * data
chunk of memory for msg data
int svm_queue_sub_raw(svm_queue_t *q, u8 *elem)
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)
#define vec_foreach(var, vec)
Vector iterator.
int consumer_pid
pid of msg consumer
#define CLIB_CACHE_LINE_BYTES
static int svm_msg_q_lock(svm_msg_q_t *mq)
Lock, or block trying, the message queue.
svm_msg_q_msg_t svm_msg_q_alloc_msg_w_ring(svm_msg_q_t *mq, u32 ring_index)
Allocate message buffer on ring.
static void * svm_msg_q_ring_data(svm_msg_q_ring_t *ring, u32 elt_index)
void svm_msg_q_sub_w_lock(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Consumer dequeue one message from queue with mutex held.
u32 nitems
max size of the ring