From abd8b36d19408403a40d24aa411686d52011a844 Mon Sep 17 00:00:00 2001 From: nandfan Date: Thu, 25 Mar 2021 14:24:53 +0800 Subject: 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 Signed-off-by: Florin Coras Change-Id: Ib90b87ab76534cd42e9a4c3e11703e80d93ca678 --- src/svm/message_queue.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/svm') 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 { -- cgit 1.2.3-korg