diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index 473653d4562c11..ed1bf643465ed9 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -33,8 +33,6 @@ #include #include -#include - #include #include #include @@ -190,11 +188,13 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() this->mpGDBusConnection = UniqueGDBusConnection(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error)); std::thread gdbusThread(GDBus_Thread); + mGdbusThreadHandle = gdbusThread.native_handle(); gdbusThread.detach(); #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI std::thread wifiIPThread(WiFIIPChangeListener); + mWifiIPThreadHandle = wifiIPThread.native_handle(); wifiIPThread.detach(); #endif @@ -217,6 +217,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() CHIP_ERROR PlatformManagerImpl::_Shutdown() { + CHIP_ERROR err; uint64_t upTime = 0; if (GetDiagnosticDataProvider().GetUpTime(upTime) == CHIP_NO_ERROR) @@ -237,7 +238,23 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() ChipLogError(DeviceLayer, "Failed to get current uptime since the Node’s last reboot"); } - return Internal::GenericPlatformManagerImpl_POSIX::_Shutdown(); + err = Internal::GenericPlatformManagerImpl_POSIX::_Shutdown(); + +#if CHIP_WITH_GIO + if (pthread_cancel(mGdbusThreadHandle) != 0) + { + ChipLogError(DeviceLayer, "Failed to cancel gDBus thread"); + } +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + if (pthread_cancel(mWifiIPThreadHandle) != 0) + { + ChipLogError(DeviceLayer, "Failed to cancel WiFI IP Change Listener thread"); + } +#endif + + return err; } CHIP_ERROR PlatformManagerImpl::_GetFixedLabelList( diff --git a/src/platform/Linux/PlatformManagerImpl.h b/src/platform/Linux/PlatformManagerImpl.h index b6320ff734cb5b..15b001ac46a518 100644 --- a/src/platform/Linux/PlatformManagerImpl.h +++ b/src/platform/Linux/PlatformManagerImpl.h @@ -30,6 +30,8 @@ #include #endif +#include + namespace chip { namespace DeviceLayer { @@ -97,6 +99,12 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener }; using UniqueGDBusConnection = std::unique_ptr; UniqueGDBusConnection mpGDBusConnection; + + std::thread::native_handle_type mGdbusThreadHandle; +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + std::thread::native_handle_type mWifiIPThreadHandle; #endif };