From cdb2e3f279f05ed85a68a727e61a4ff40993a040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Bo=C4=8Dek?= Date: Wed, 10 Jul 2024 20:28:55 +0200 Subject: [PATCH] fix: freeRTOSEventQueue queue draining on shutdown --- main/espFeatures/freeRTOSEventQueue.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main/espFeatures/freeRTOSEventQueue.h b/main/espFeatures/freeRTOSEventQueue.h index 800791e..35f39fc 100644 --- a/main/espFeatures/freeRTOSEventQueue.h +++ b/main/espFeatures/freeRTOSEventQueue.h @@ -126,6 +126,15 @@ class FreeRTOSEventQueueFeature : public Next { } } + void drain() { + while(true) { + Event e; + if(xQueueReceive(_eventQueue, &e, 0) == pdFALSE) { + break; + } + } + } + void _scheduleImpl(auto&&... args) { Event e(std::forward(args)...); auto res = xQueueSend(_eventQueue, &e, portMAX_DELAY); @@ -217,8 +226,7 @@ class FreeRTOSEventQueueFeature : public Next { } ~FreeRTOSEventQueueFeature() { - notifyEventLoop(); - while (dequeue(false)) {} + drain(); vQueueDelete(_eventQueue); } };