From e33d6fb5bcf14ad4726c55b0d50ee43a408fd474 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 7 Sep 2022 13:59:45 -0400 Subject: [PATCH] Address review comments. --- .restyled.yaml | 2 + .../GenericPlatformManagerImpl_FreeRTOS.h | 6 +- .../GenericPlatformManagerImpl_FreeRTOS.ipp | 56 ++++++++++--------- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/.restyled.yaml b/.restyled.yaml index c45fe98588b7ec..d4ca39f3efa448 100644 --- a/.restyled.yaml +++ b/.restyled.yaml @@ -98,6 +98,7 @@ restylers: - "**/*.c" - "**/*.cc" - "**/*.cpp" + - "**/*.ipp" - "**/*.cxx" - "**/*.c++" - "**/*.C" @@ -137,6 +138,7 @@ restylers: - "**/*.c" - "**/*.cc" - "**/*.cpp" + - "**/*.ipp" - "**/*.cxx" - "**/*.c++" - "**/*.C" diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h index 617e5caa39fa33..f1a400fc884efd 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h @@ -60,9 +60,9 @@ class GenericPlatformManagerImpl_FreeRTOS : public GenericPlatformManagerImpl::_InitChipStack(void) vTaskSetTimeOutState(&mNextTimerBaseTime); mNextTimerDurationTicks = 0; - mEventLoopTask = NULL; - mChipTimerActive = false; + // TODO: This nulling out of mEventLoopTask should happen when we shut down + // the task, not here! + mEventLoopTask = NULL; + mChipTimerActive = false; + // We support calling Shutdown followed by InitChipStack, because some tests + // do that. To keep things simple for existing consumers, we keep not + // destroying our lock and queue in shutdown, but rather check whether they + // already exist here before trying to create them. + + if (mChipStackLock == NULL) + { #if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE) && CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE - mChipStackLock = xSemaphoreCreateMutexStatic(&mChipStackLockMutex); + mChipStackLock = xSemaphoreCreateMutexStatic(&mChipStackLockMutex); #else - mChipStackLock = xSemaphoreCreateMutex(); + mChipStackLock = xSemaphoreCreateMutex(); #endif // CHIP_CONFIG_FREERTOS_USE_STATIC_SEMAPHORE - if (mChipStackLock == NULL) - { - ChipLogError(DeviceLayer, "Failed to create CHIP stack lock"); - ExitNow(err = CHIP_ERROR_NO_MEMORY); + if (mChipStackLock == NULL) + { + ChipLogError(DeviceLayer, "Failed to create CHIP stack lock"); + ExitNow(err = CHIP_ERROR_NO_MEMORY); + } } + if (mChipEventQueue == NULL) + { #if defined(CHIP_CONFIG_FREERTOS_USE_STATIC_QUEUE) && CHIP_CONFIG_FREERTOS_USE_STATIC_QUEUE - mChipEventQueue = - xQueueCreateStatic(CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE, sizeof(ChipDeviceEvent), mEventQueueBuffer, &mEventQueueStruct); + mChipEventQueue = xQueueCreateStatic(CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE, sizeof(ChipDeviceEvent), mEventQueueBuffer, + &mEventQueueStruct); #else - mChipEventQueue = xQueueCreate(CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE, sizeof(ChipDeviceEvent)); + mChipEventQueue = xQueueCreate(CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE, sizeof(ChipDeviceEvent)); #endif - if (mChipEventQueue == NULL) - { - ChipLogError(DeviceLayer, "Failed to allocate CHIP event queue"); - ExitNow(err = CHIP_ERROR_NO_MEMORY); + if (mChipEventQueue == NULL) + { + ChipLogError(DeviceLayer, "Failed to allocate CHIP event queue"); + ExitNow(err = CHIP_ERROR_NO_MEMORY); + } } mShouldRunEventLoop.store(false); @@ -236,6 +249,9 @@ void GenericPlatformManagerImpl_FreeRTOS::EventLoopTaskMain(void * ar { ChipLogDetail(DeviceLayer, "CHIP task running"); static_cast *>(arg)->Impl()->RunEventLoop(); + // TODO: At this point, should we not + // vTaskDelete(static_cast *>(arg)->mEventLoopTask)? + // Or somehow get our caller to do it once this thread is joined? } template @@ -276,16 +292,6 @@ template void GenericPlatformManagerImpl_FreeRTOS::_Shutdown(void) { GenericPlatformManagerImpl::_Shutdown(); - - if (mChipEventQueue != NULL) { - vQueueDelete(mChipEventQueue); - mChipEventQueue = NULL; - } - - if (mChipStackLock != NULL) { - vSemaphoreDelete(mChipStackLock); - mChipStackLock = NULL; - } } template