diff options
Diffstat (limited to 'src/svm/message_queue.h')
-rw-r--r-- | src/svm/message_queue.h | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/svm/message_queue.h b/src/svm/message_queue.h index 50f79fb0c19..4b314b837e9 100644 --- a/src/svm/message_queue.h +++ b/src/svm/message_queue.h @@ -24,16 +24,30 @@ #include <vppinfra/error.h> #include <svm/queue.h> -typedef struct svm_msg_q_ring_ +typedef struct svm_msg_q_ring_shared_ { volatile u32 cursize; /**< current size of the ring */ u32 nitems; /**< max size of the ring */ volatile u32 head; /**< current head (for dequeue) */ volatile u32 tail; /**< current tail (for enqueue) */ u32 elsize; /**< size of an element */ - u8 *data; /**< chunk of memory for msg data */ + u8 data[0]; /**< chunk of memory for msg data */ +} svm_msg_q_ring_shared_t; + +typedef struct svm_msg_q_ring_ +{ + u32 nitems; /**< max size of the ring */ + u32 elsize; /**< size of an element */ + svm_msg_q_ring_shared_t *shr; /**< ring in shared memory */ } __clib_packed svm_msg_q_ring_t; +typedef struct svm_msg_q_shared_ +{ + u32 n_rings; /**< number of rings after q */ + u32 pad; /**< 8 byte alignment for q */ + svm_queue_t q[0]; /**< queue for exchanging messages */ +} __clib_packed svm_msg_q_shared_t; + typedef struct svm_msg_q_ { svm_queue_t *q; /**< queue for exchanging messages */ @@ -77,10 +91,12 @@ typedef union * ring configs * @return message queue */ -svm_msg_q_t *svm_msg_q_alloc (svm_msg_q_cfg_t * cfg); -svm_msg_q_t *svm_msg_q_init (void *base, svm_msg_q_cfg_t *cfg); +svm_msg_q_shared_t *svm_msg_q_alloc (svm_msg_q_cfg_t *cfg); +svm_msg_q_shared_t *svm_msg_q_init (void *base, svm_msg_q_cfg_t *cfg); uword svm_msg_q_size_to_alloc (svm_msg_q_cfg_t *cfg); +void svm_msg_q_attach (svm_msg_q_t *mq, void *smq_base); + /** * Free message queue * @@ -267,8 +283,8 @@ svm_msg_q_is_full (svm_msg_q_t * mq) static inline u8 svm_msg_q_ring_is_full (svm_msg_q_t * mq, u32 ring_index) { - ASSERT (ring_index < vec_len (mq->rings)); - return (mq->rings[ring_index].cursize == mq->rings[ring_index].nitems); + svm_msg_q_ring_t *ring = vec_elt_at_index (mq->rings, ring_index); + return (ring->shr->cursize >= ring->nitems); } /** |