diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index de7d1a343ec2e4..767a378d080dba 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -33,8 +33,6 @@ #include #include -#include - #include #include #include @@ -210,6 +208,9 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() { CHIP_ERROR err; struct sigaction action; +#if CHIP_WITH_GIO + GError * error = nullptr; +#endif memset(&action, 0, sizeof(action)); action.sa_handler = SignalHandler; @@ -220,20 +221,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() sigaction(SIGUSR2, &action, NULL); sigaction(SIGTSTP, &action, NULL); -#if CHIP_WITH_GIO - GError * error = nullptr; - - this->mpGDBusConnection = UniqueGDBusConnection(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error)); - - std::thread gdbusThread(GDBus_Thread); - gdbusThread.detach(); -#endif - -#if CHIP_DEVICE_CONFIG_ENABLE_WIFI - std::thread wifiIPThread(WiFIIPChangeListener); - wifiIPThread.detach(); -#endif - // Initialize the configuration system. err = Internal::PosixConfig::Init(); SuccessOrExit(err); @@ -247,6 +234,16 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() mStartTime = System::SystemClock().GetMonotonicTimestamp(); +#if CHIP_WITH_GIO + this->mpGDBusConnection = UniqueGDBusConnection(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error)); + + mGdbusThread = std::thread(GDBus_Thread); +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + mWifiIPThread = std::thread(WiFIIPChangeListener); +#endif + exit: return err; } @@ -273,6 +270,20 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() ChipLogError(DeviceLayer, "Failed to get current uptime since the Node’s last reboot"); } +#if CHIP_WITH_GIO + if (mGdbusThread.joinable()) + { + mGdbusThread.join(); + } +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + if (mWifiIPThread.joinable()) + { + mWifiIPThread.join(); + } +#endif + return Internal::GenericPlatformManagerImpl_POSIX::_Shutdown(); } diff --git a/src/platform/Linux/PlatformManagerImpl.h b/src/platform/Linux/PlatformManagerImpl.h index b6320ff734cb5b..712e7b5b6911a9 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 mGdbusThread; +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI + std::thread mWifiIPThread; #endif };