X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fsvm%2Fqueue.c;h=96e40fc2aec749940e32f110d75aefbd062f725e;hb=3fca567ff438145e28dd1318ad5b1734c1091257;hp=aef409277db34c6802445c869f1509711de679ed;hpb=e82488f10f20f464961c5c7b381b4a419bca0bbc;p=vpp.git diff --git a/src/svm/queue.c b/src/svm/queue.c index aef409277db..96e40fc2aec 100644 --- a/src/svm/queue.c +++ b/src/svm/queue.c @@ -26,6 +26,7 @@ #include #include #include +#include #include /* @@ -299,12 +300,14 @@ svm_queue_add2 (svm_queue_t * q, u8 * elem, u8 * elem2, int nowait) * svm_queue_sub */ int -svm_queue_sub (svm_queue_t * q, u8 * elem, int nowait) +svm_queue_sub (svm_queue_t * q, u8 * elem, svm_q_conditional_wait_t cond, + u32 time) { i8 *headp; int need_broadcast = 0; + int rc = 0; - if (nowait) + if (cond == SVM_Q_NOWAIT) { /* zero on success */ if (pthread_mutex_trylock (&q->mutex)) @@ -317,14 +320,32 @@ svm_queue_sub (svm_queue_t * q, u8 * elem, int nowait) if (PREDICT_FALSE (q->cursize == 0)) { - if (nowait) + if (cond == SVM_Q_NOWAIT) { pthread_mutex_unlock (&q->mutex); return (-2); } - while (q->cursize == 0) + else if (cond == SVM_Q_TIMEDWAIT) { - (void) pthread_cond_wait (&q->condvar, &q->mutex); + struct timespec ts; + ts.tv_sec = unix_time_now () + time; + ts.tv_nsec = 0; + while (q->cursize == 0 && rc == 0) + { + rc = pthread_cond_timedwait (&q->condvar, &q->mutex, &ts); + } + if (rc == ETIMEDOUT) + { + pthread_mutex_unlock (&q->mutex); + return ETIMEDOUT; + } + } + else + { + while (q->cursize == 0) + { + (void) pthread_cond_wait (&q->condvar, &q->mutex); + } } }