X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fsvm%2Fmessage_queue.h;h=4c16c97ca7c418639eda0aedc279b2632d2c7d17;hb=54693d23307ce8944a4d97379efd3bd4dcf0485c;hp=e4a5f07d4800c245fcaca0bb12f9ddf92a4fa8e4;hpb=5df580eec93c0c6fc07dd38f8713f671565b9c38;p=vpp.git diff --git a/src/svm/message_queue.h b/src/svm/message_queue.h index e4a5f07d480..4c16c97ca7c 100644 --- a/src/svm/message_queue.h +++ b/src/svm/message_queue.h @@ -22,6 +22,7 @@ #include #include +#include #include typedef struct svm_msg_q_ring_ @@ -274,12 +275,6 @@ svm_msg_q_lock (svm_msg_q_t * mq) 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 */ @@ -292,6 +287,37 @@ svm_msg_q_unlock (svm_msg_q_t * mq) 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_ */ /*