diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 2991a32dbbb3cb..8422f5508d4bf3 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +106,8 @@ DeviceController::DeviceController() CHIP_ERROR DeviceController::Init(ControllerInitParams params) { + assertChipStackLockedByCurrentThread(); + VerifyOrReturnError(mState == State::NotInitialized, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(params.systemState != nullptr, CHIP_ERROR_INVALID_ARGUMENT); @@ -282,6 +285,8 @@ CHIP_ERROR DeviceController::InitControllerNOCChain(const ControllerInitParams & void DeviceController::Shutdown() { + assertChipStackLockedByCurrentThread(); + VerifyOrReturn(mState != State::NotInitialized); ChipLogDetail(Controller, "Shutting down the controller"); diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.h b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.h index bf04f5498d2d88..7fd248fdf699d9 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.h @@ -77,7 +77,6 @@ class GenericPlatformManagerImpl_POSIX : public GenericPlatformManagerImpl::_UnlockChipStack() template bool GenericPlatformManagerImpl_POSIX::_IsChipStackLockedByCurrentThread() const { - return !mMainLoopStarted || (mChipStackIsLocked && (pthread_equal(pthread_self(), mChipStackLockOwnerThread))); + return !mHasValidChipTask || (mChipStackIsLocked && (pthread_equal(pthread_self(), mChipStackLockOwnerThread))); } #endif @@ -201,7 +201,6 @@ template void * GenericPlatformManagerImpl_POSIX::EventLoopTaskMain(void * arg) { ChipLogDetail(DeviceLayer, "CHIP task running"); - static_cast *>(arg)->Impl()->mMainLoopStarted = true; static_cast *>(arg)->Impl()->RunEventLoop(); return nullptr; }