From 094197ba905876de9a7d32a7a81fd62905ce33e2 Mon Sep 17 00:00:00 2001 From: caochao Date: Thu, 17 Feb 2022 10:58:56 +0800 Subject: [PATCH] fixed 25adbdb from https://gitee.com/caochao123/distributedschedule_samgr_lite/pulls/52 modify queue_pop race condition Signed-off-by: caochao Change-Id: Ib252acd48550d5873a2eb58a8743296b3532ba64 --- samgr/adapter/posix/queue_adapter.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samgr/adapter/posix/queue_adapter.c b/samgr/adapter/posix/queue_adapter.c index da7f031..376296e 100644 --- a/samgr/adapter/posix/queue_adapter.c +++ b/samgr/adapter/posix/queue_adapter.c @@ -67,9 +67,11 @@ int QUEUE_Pop(MQueueId queueId, void *element, uint8 *pri, int timeout) LockFreeBlockQueue *queue = (LockFreeBlockQueue *)queueId; pthread_mutex_lock(&queue->rMutex); if (LFQUE_Pop(queue->queue, element, pri) == EC_SUCCESS) { + pthread_mutex_unlock(&queue->rMutex); return EC_SUCCESS; } + pthread_mutex_lock(&queue->rMutex); while (LFQUE_Pop(queue->queue, element, pri) != EC_SUCCESS) { pthread_cond_wait(&queue->cond, &queue->rMutex); } -- Gitee