From 4b366e26f14627e2f15be852e2c5934b6e327fa1 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 8 Aug 2022 16:34:13 -0400 Subject: [PATCH] Make sure chip-tool interactive cleanup happens on the Matter thread. (#21661) The interactive cleanup happens while the event loop is still running (during the execution of the "interactive" command), so queuing the cleanup on the event loop is reasonable. And this ensures cleanups don't run into MAtter locking assertions. --- examples/chip-tool/commands/common/CHIPCommand.cpp | 2 +- examples/chip-tool/commands/common/CHIPCommand.h | 2 +- examples/chip-tool/commands/interactive/InteractiveCommands.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 8649efc69358f9..e511ebb9795325 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -453,7 +453,7 @@ void CHIPCommand::StopWaiting() #endif // CONFIG_USE_SEPARATE_EVENTLOOP } -void CHIPCommand::ExecuteDeferredCleanups() +void CHIPCommand::ExecuteDeferredCleanups(intptr_t ignored) { for (auto * cmd : sDeferredCleanups) { diff --git a/examples/chip-tool/commands/common/CHIPCommand.h b/examples/chip-tool/commands/common/CHIPCommand.h index 7688a34873bfbe..02a30eb28ee2dc 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.h +++ b/examples/chip-tool/commands/common/CHIPCommand.h @@ -115,7 +115,7 @@ class CHIPCommand : public Command virtual bool DeferInteractiveCleanup() { return false; } // Execute any deferred cleanups. Used when exiting interactive mode. - void ExecuteDeferredCleanups(); + static void ExecuteDeferredCleanups(intptr_t ignored); #ifdef CONFIG_USE_LOCAL_STORAGE PersistentStorage mDefaultStorage; diff --git a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp index 33b030acb335c7..38e706b119e056 100644 --- a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp +++ b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp @@ -89,7 +89,7 @@ bool InteractiveStartCommand::ParseCommand(char * command) { if (strcmp(command, kInteractiveModeStopCommand) == 0) { - ExecuteDeferredCleanups(); + chip::DeviceLayer::PlatformMgr().ScheduleWork(ExecuteDeferredCleanups, 0); return false; }