#include <vppinfra/clib.h>
#include <vppinfra/error.h>
+#include <vppinfra/time.h>
#include <svm/queue.h>
typedef struct svm_msg_q_ring_
volatile u32 tail; /**< current tail (for enqueue) */
u32 elsize; /**< size of an element */
u8 *data; /**< chunk of memory for msg data */
-} svm_msg_q_ring_t;
+} __clib_packed svm_msg_q_ring_t;
typedef struct svm_msg_q_
{
svm_queue_t *q; /**< queue for exchanging messages */
svm_msg_q_ring_t *rings; /**< rings with message data*/
-} svm_msg_q_t;
+} __clib_packed svm_msg_q_t;
typedef struct svm_msg_q_ring_cfg_
{
return pthread_mutex_lock (&mq->q->mutex);
}
-static inline void
-svm_msg_q_wait (svm_msg_q_t * mq)
-{
- pthread_cond_wait (&mq->q->condvar, &mq->q->mutex);
-}
-
/**
* Unlock message queue
*/
pthread_mutex_unlock (&mq->q->mutex);
}
+/**
+ * Wait for message queue event
+ *
+ * Must be called with mutex held
+ */
+static inline void
+svm_msg_q_wait (svm_msg_q_t * mq)
+{
+ pthread_cond_wait (&mq->q->condvar, &mq->q->mutex);
+}
+
+/**
+ * Timed wait for message queue event
+ *
+ * Must be called with mutex held.
+ *
+ * @param mq message queue
+ * @param timeout time in seconds
+ */
+static inline int
+svm_msg_q_timedwait (svm_msg_q_t * mq, double timeout)
+{
+ struct timespec ts;
+
+ ts.tv_sec = unix_time_now () + (u32) timeout;
+ ts.tv_nsec = (timeout - (u32) timeout) * 1e9;
+ if (pthread_cond_timedwait (&mq->q->condvar, &mq->q->mutex, &ts))
+ return -1;
+ return 0;
+}
+
#endif /* SRC_SVM_MESSAGE_QUEUE_H_ */
/*