20 #ifndef SRC_SVM_MESSAGE_QUEUE_H_ 21 #define SRC_SVM_MESSAGE_QUEUE_H_ 68 #define SVM_MQ_INVALID_MSG { .as_u64 = ~0 } 262 return (mq->
q->cursize == mq->
q->maxsize);
278 return (mq->
q->cursize == 0);
287 return mq->
q->cursize;
305 return pthread_mutex_trylock (&mq->
q->mutex);
314 return pthread_mutex_lock (&mq->
q->mutex);
323 pthread_mutex_unlock (&mq->
q->mutex);
355 return mq->
q->consumer_evtfd;
361 return mq->
q->producer_evtfd;
static u8 svm_msg_q_msg_is_invalid(svm_msg_q_msg_t *msg)
Check if message is invalid.
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.
svm_msg_q_ring_t * rings
rings with message data
static u8 svm_msg_q_ring_is_full(svm_msg_q_t *mq, u32 ring_index)
u8 * format_svm_msg_q(u8 *s, va_list *args)
Format message queue, shows msg count for each ring.
void svm_msg_q_set_consumer_eventfd(svm_msg_q_t *mq, int fd)
Set event fd for queue consumer.
static int svm_msg_q_get_producer_eventfd(svm_msg_q_t *mq)
static u8 svm_msg_q_is_empty(svm_msg_q_t *mq)
Check if message queue is empty.
volatile u32 head
current head (for dequeue)
svm_msg_q_msg_t svm_msg_q_alloc_msg(svm_msg_q_t *mq, u32 nbytes)
Allocate message buffer.
void svm_msg_q_set_producer_eventfd(svm_msg_q_t *mq, int fd)
Set event fd for queue producer.
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queue.
volatile u32 tail
current tail (for enqueue)
svm_msg_q_t * svm_msg_q_alloc(svm_msg_q_cfg_t *cfg)
Allocate message queue.
void svm_queue_wait(svm_queue_t *q)
Wait for queue event.
struct svm_msg_q_cfg_ svm_msg_q_cfg_t
static void svm_msg_q_wait(svm_msg_q_t *mq)
Wait for message queue event.
volatile u32 cursize
current size of the ring
struct svm_msg_q_ring_ svm_msg_q_ring_t
struct svm_msg_q_ring_cfg_ svm_msg_q_ring_cfg_t
u32 n_rings
number of msg rings
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
static int svm_msg_q_timedwait(svm_msg_q_t *mq, double timeout)
Timed wait for message queue event.
svm_queue_t * q
queue for exchanging messages
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.
u32 elt_index
index in ring
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 int svm_msg_q_try_lock(svm_msg_q_t *mq)
Try locking message queue.
u32 ring_index
ring index, could be u8
static int svm_msg_q_get_consumer_eventfd(svm_msg_q_t *mq)
int svm_msg_q_alloc_producer_eventfd(svm_msg_q_t *mq)
Allocate event fd for queue consumer.
struct svm_msg_q_ svm_msg_q_t
u8 * data
chunk of memory for msg data
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.
int svm_msg_q_add(svm_msg_q_t *mq, svm_msg_q_msg_t *msg, int nowait)
Producer enqueue one message to queue.
svm_msg_q_ring_cfg_t * ring_cfgs
array of ring cfgs
u32 q_nitems
msg queue size (not rings)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
int svm_msg_q_alloc_consumer_eventfd(svm_msg_q_t *mq)
Allocate event fd for queue consumer.
void svm_msg_q_free_msg(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Free message buffer.
struct _svm_queue svm_queue_t
u32 elsize
size of an element
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.
static u32 svm_msg_q_size(svm_msg_q_t *mq)
Check length of message queue.
svm_msg_q_ring_t * svm_msg_q_ring(svm_msg_q_t *mq, u32 ring_index)
Get message queue ring.
int svm_queue_timedwait(svm_queue_t *q, double timeout)
Timed wait for queue event.
int consumer_pid
pid of msg consumer
static int svm_msg_q_lock(svm_msg_q_t *mq)
Lock, or block trying, the message queue.
static u8 svm_msg_q_is_full(svm_msg_q_t *mq)
Check if message queue is full.
void svm_msg_q_free(svm_msg_q_t *mq)
Free message queue.
u32 nitems
max size of the ring