aboutsummaryrefslogtreecommitdiffstats
path: root/src/svm/message_queue.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2022-04-19 18:57:24 -0700
committerDave Barach <openvpp@barachs.net>2022-04-21 16:48:15 +0000
commit80d100cd59015d91c4f0abfaf07b6876088ecbf1 (patch)
tree5b0d949fcf012b359c0af8b4371afbe6d10c7a29 /src/svm/message_queue.c
parent5297447bd64ab253ab3ab3e144605dd39f995f12 (diff)
session svm: fix mq producer wait on q and ring
Make sure producer drops lock when it waits for empty ring slot. Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: Id77d54ee8c01bed20c9eaf5ad372ed4b1e9fa712
Diffstat (limited to 'src/svm/message_queue.c')
-rw-r--r--src/svm/message_queue.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/svm/message_queue.c b/src/svm/message_queue.c
index a6af7962f73..2880645b427 100644
--- a/src/svm/message_queue.c
+++ b/src/svm/message_queue.c
@@ -243,8 +243,7 @@ svm_msg_q_lock_and_alloc_msg_w_ring (svm_msg_q_t * mq, u32 ring_index,
{
if (svm_msg_q_try_lock (mq))
return -1;
- if (PREDICT_FALSE (svm_msg_q_is_full (mq)
- || svm_msg_q_ring_is_full (mq, ring_index)))
+ if (PREDICT_FALSE (svm_msg_q_or_ring_is_full (mq, ring_index)))
{
svm_msg_q_unlock (mq);
return -2;
@@ -254,9 +253,8 @@ svm_msg_q_lock_and_alloc_msg_w_ring (svm_msg_q_t * mq, u32 ring_index,
else
{
svm_msg_q_lock (mq);
- while (svm_msg_q_is_full (mq)
- || svm_msg_q_ring_is_full (mq, ring_index))
- svm_msg_q_wait_prod (mq);
+ while (svm_msg_q_or_ring_is_full (mq, ring_index))
+ svm_msg_q_or_ring_wait_prod (mq, ring_index);
*msg = svm_msg_q_alloc_msg_w_ring (mq, ring_index);
}
return 0;
@@ -569,6 +567,35 @@ svm_msg_q_wait_prod (svm_msg_q_t *mq)
}
int
+svm_msg_q_or_ring_wait_prod (svm_msg_q_t *mq, u32 ring_index)
+{
+ if (mq->q.evtfd == -1)
+ {
+ while (svm_msg_q_or_ring_is_full (mq, ring_index))
+ pthread_cond_wait (&mq->q.shr->condvar, &mq->q.shr->mutex);
+ }
+ else
+ {
+ u64 buf;
+ int rv;
+
+ while (svm_msg_q_or_ring_is_full (mq, ring_index))
+ {
+ while ((rv = read (mq->q.evtfd, &buf, sizeof (buf))) < 0)
+ {
+ if (errno != EAGAIN)
+ {
+ clib_unix_warning ("read error");
+ return rv;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+int
svm_msg_q_timedwait (svm_msg_q_t *mq, double timeout)
{
if (mq->q.evtfd == -1)