aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornandfan <fanyufei521@outlook.com>2021-03-25 14:24:53 +0800
committerFlorin Coras <florin.coras@gmail.com>2021-03-25 19:54:18 +0000
commitabd8b36d19408403a40d24aa411686d52011a844 (patch)
treec41e12b946a922a65957da1b9e265abc9d5b14a7 /src
parent418bf6aaef6048d15bc1f575a166e8f5e52696be (diff)
svm: fix producer deadlock in svm_msg_q_wait()
1. When producer invokes svm_msg_q_wait() in svm_msg_q_lock_and_alloc_msg_w_ring(), queue mutex is held by itself. 2. Sometimes, svm msg queue is not full and ring is full, svm_msg_q_wait() do nothing with mutex held, consumer will blocking at svm_msg_q_send_signal(). Type: fix Signed-off-by: nandfan <fanyufei521@outlook.com> Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: Ib90b87ab76534cd42e9a4c3e11703e80d93ca678
Diffstat (limited to 'src')
-rw-r--r--src/svm/message_queue.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/svm/message_queue.c b/src/svm/message_queue.c
index 8be6be7686f..3163d302967 100644
--- a/src/svm/message_queue.c
+++ b/src/svm/message_queue.c
@@ -498,17 +498,21 @@ svm_msg_q_wait (svm_msg_q_t *mq, svm_msg_q_wait_type_t type)
if (mq->q.evtfd == -1)
{
- rv = pthread_mutex_lock (&mq->q.shr->mutex);
- if (PREDICT_FALSE (rv == EOWNERDEAD))
+ if (type == SVM_MQ_WAIT_EMPTY)
{
- rv = pthread_mutex_consistent (&mq->q.shr->mutex);
- return rv;
+ rv = pthread_mutex_lock (&mq->q.shr->mutex);
+ if (PREDICT_FALSE (rv == EOWNERDEAD))
+ {
+ rv = pthread_mutex_consistent (&mq->q.shr->mutex);
+ return rv;
+ }
}
while (fn (mq))
pthread_cond_wait (&mq->q.shr->condvar, &mq->q.shr->mutex);
- pthread_mutex_unlock (&mq->q.shr->mutex);
+ if (type == SVM_MQ_WAIT_EMPTY)
+ pthread_mutex_unlock (&mq->q.shr->mutex);
}
else
{