From cbeb44b1644f08359f12b9657fc481c164a0baa7 Mon Sep 17 00:00:00 2001 From: baoguotao Date: Wed, 6 Apr 2022 15:11:30 +0800 Subject: [PATCH] fix: optimization of hdf message looper exit mechanism Signed-off-by: baoguotao --- utils/include/hdf_message_looper.h | 1 + utils/src/hdf_message_looper.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/include/hdf_message_looper.h b/utils/include/hdf_message_looper.h index d11d79a9..dcfd4deb 100644 --- a/utils/include/hdf_message_looper.h +++ b/utils/include/hdf_message_looper.h @@ -21,6 +21,7 @@ struct HdfMessageLooper { struct HdfMessageQueue messageQueue; void (*Start)(struct HdfMessageLooper *); void (*Stop)(struct HdfMessageLooper *); + bool isRunning; }; void HdfMessageLooperConstruct(struct HdfMessageLooper *looper); diff --git a/utils/src/hdf_message_looper.c b/utils/src/hdf_message_looper.c index b9aa190e..209250d4 100644 --- a/utils/src/hdf_message_looper.c +++ b/utils/src/hdf_message_looper.c @@ -13,12 +13,17 @@ void HdfMessageLooperStart(struct HdfMessageLooper *looper) { struct HdfMessage *message = NULL; - while (looper != NULL) { + if (looper == NULL) { + return; + } + looper->isRunning = true; + while (true) { message = HdfMessageQueueNext(&looper->messageQueue); if (message != NULL) { if (message->messageId == MESSAGE_STOP_LOOP) { HdfMessageRecycle(message); OsalMessageQueueDestroy(&looper->messageQueue); + looper->isRunning = false; break; } else if (message->target != NULL) { struct HdfMessageTask *task = message->target; @@ -31,7 +36,7 @@ void HdfMessageLooperStart(struct HdfMessageLooper *looper) void HdfMessageLooperStop(struct HdfMessageLooper *looper) { - if (looper == NULL) { + if (looper == NULL || !looper->isRunning) { return; }