Skip to content

Commit ccbc1f2

Browse files
Delete the ChipEventQueue and BackgroundEventQueue after returning from the event loop. (project-chip#37489)
* Delete the ChipEventQueue and BackgroundEventQueue after returning from the event loop * Addressed review comments. * Delete event queues in the shutdown. * Delete the ChipLock mutex as well in the shutdown.
1 parent 0086ee2 commit ccbc1f2

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.ipp

+25-17
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,7 @@ CHIP_ERROR GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_InitChipStack(void)
4646

4747
vTaskSetTimeOutState(&mNextTimerBaseTime);
4848
mNextTimerDurationTicks = 0;
49-
// TODO: This nulling out of mEventLoopTask should happen when we shut down
50-
// the task, not here!
51-
mEventLoopTask = NULL;
52-
#if defined(CHIP_DEVICE_CONFIG_ENABLE_BG_EVENT_PROCESSING) && CHIP_DEVICE_CONFIG_ENABLE_BG_EVENT_PROCESSING
53-
mBackgroundEventLoopTask = NULL;
54-
#endif
55-
mChipTimerActive = false;
56-
57-
// We support calling Shutdown followed by InitChipStack, because some tests
58-
// do that. To keep things simple for existing consumers, we keep not
59-
// destroying our lock and queue in shutdown, but rather check whether they
60-
// already exist here before trying to create them.
49+
mChipTimerActive = false;
6150

6251
if (mChipStackLock == NULL)
6352
{
@@ -277,10 +266,11 @@ template <class ImplClass>
277266
void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::EventLoopTaskMain(void * arg)
278267
{
279268
ChipLogDetail(DeviceLayer, "CHIP event task running");
280-
static_cast<GenericPlatformManagerImpl_FreeRTOS<ImplClass> *>(arg)->Impl()->RunEventLoop();
281-
// TODO: At this point, should we not
282-
// vTaskDelete(static_cast<GenericPlatformManagerImpl_FreeRTOS<ImplClass> *>(arg)->mEventLoopTask)?
283-
// Or somehow get our caller to do it once this thread is joined?
269+
GenericPlatformManagerImpl_FreeRTOS<ImplClass> * platformManager =
270+
static_cast<GenericPlatformManagerImpl_FreeRTOS<ImplClass> *>(arg);
271+
platformManager->Impl()->RunEventLoop();
272+
vTaskDelete(NULL);
273+
platformManager->mEventLoopTask = NULL;
284274
}
285275

286276
template <class ImplClass>
@@ -376,7 +366,11 @@ template <class ImplClass>
376366
void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::BackgroundEventLoopTaskMain(void * arg)
377367
{
378368
ChipLogDetail(DeviceLayer, "CHIP background task running");
379-
static_cast<GenericPlatformManagerImpl_FreeRTOS<ImplClass> *>(arg)->Impl()->RunBackgroundEventLoop();
369+
GenericPlatformManagerImpl_FreeRTOS<ImplClass> * platformManager =
370+
static_cast<GenericPlatformManagerImpl_FreeRTOS<ImplClass> *>(arg);
371+
platformManager->Impl()->RunBackgroundEventLoop();
372+
vTaskDelete(NULL);
373+
platformManager->mBackgroundEventLoopTask = NULL;
380374
}
381375
#endif
382376

@@ -416,6 +410,20 @@ void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::PostEventFromISR(const Chip
416410
template <class ImplClass>
417411
void GenericPlatformManagerImpl_FreeRTOS<ImplClass>::_Shutdown(void)
418412
{
413+
if (mChipEventQueue)
414+
{
415+
vQueueDelete(mChipEventQueue);
416+
mChipEventQueue = NULL;
417+
}
418+
#if defined(CHIP_DEVICE_CONFIG_ENABLE_BG_EVENT_PROCESSING) && CHIP_DEVICE_CONFIG_ENABLE_BG_EVENT_PROCESSING
419+
if (mBackgroundEventQueue)
420+
{
421+
vQueueDelete(mBackgroundEventQueue);
422+
mBackgroundEventQueue = NULL;
423+
}
424+
#endif
425+
vSemaphoreDelete(mChipStackLock);
426+
mChipStackLock = NULL;
419427
GenericPlatformManagerImpl<ImplClass>::_Shutdown();
420428
}
421429

0 commit comments

Comments
 (0)