fix: optimization of hdf message looper exit mechanism

Signed-off-by: baoguotao <baoguotao@huawei.com>
This commit is contained in:
baoguotao 2022-04-06 15:11:30 +08:00
parent d8470f621d
commit cbeb44b164
2 changed files with 8 additions and 2 deletions

View File

@ -21,6 +21,7 @@ struct HdfMessageLooper {
struct HdfMessageQueue messageQueue;
void (*Start)(struct HdfMessageLooper *);
void (*Stop)(struct HdfMessageLooper *);
bool isRunning;
};
void HdfMessageLooperConstruct(struct HdfMessageLooper *looper);

View File

@ -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;
}