svm: fix producer deadlock in svm_msg_q_wait() 59/31759/5
authornandfan <fanyufei521@outlook.com>
Thu, 25 Mar 2021 06:24:53 +0000 (14:24 +0800)
committerFlorin Coras <florin.coras@gmail.com>
Thu, 25 Mar 2021 19:54:18 +0000 (19:54 +0000)
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

src/svm/message_queue.c

index 8be6be7..3163d30 100644 (file)
@@ -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
     {