Skip to content

Commit

Permalink
Remove workarounds for threading problems from chip-tool commands. (#…
Browse files Browse the repository at this point in the history
…7434)

This change depends on
#7428 and
#7430 which fix
the problems properly.

Fixes #7408
Fixes #7409
Fixes #7410
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jun 14, 2021
1 parent 497070a commit 5400379
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
9 changes: 4 additions & 5 deletions examples/chip-tool/commands/common/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ void Commands::Register(const char * clusterName, commands_list commandsList)
}
}

// TODO: Remove this work around due to crashes when storage is accessed from multiple threads and passed around
static PersistentStorage gStorage;
int Commands::Run(NodeId localId, NodeId remoteId, int argc, char ** argv)
{
CHIP_ERROR err = CHIP_NO_ERROR;
PersistentStorage storage;

err = chip::Platform::MemoryInit();
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init Memory failure: %s", chip::ErrorStr(err)));
Expand All @@ -52,12 +51,12 @@ int Commands::Run(NodeId localId, NodeId remoteId, int argc, char ** argv)
SuccessOrExit(err = chip::DeviceLayer::Internal::BLEMgrImpl().ConfigureBle(/* BLE adapter ID */ 0, /* BLE central */ true));
#endif

err = gStorage.Init();
err = storage.Init();
VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(Controller, "Init Storage failure: %s", chip::ErrorStr(err)));

chip::Logging::SetLogFilter(gStorage.GetLoggingLevel());
chip::Logging::SetLogFilter(storage.GetLoggingLevel());

err = RunCommand(gStorage, localId, remoteId, argc, argv);
err = RunCommand(storage, localId, remoteId, argc, argv);
SuccessOrExit(err);

exit:
Expand Down
16 changes: 0 additions & 16 deletions examples/chip-tool/commands/tests/TestCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@

constexpr uint16_t kWaitDurationInSeconds = 30;

static void test_os_sleep_ms(uint64_t millisecs)
{
struct timespec sleep_time;
uint64_t s = millisecs / 1000;

millisecs -= s * 1000;
sleep_time.tv_sec = static_cast<time_t>(s);
sleep_time.tv_nsec = static_cast<long>(millisecs * 1000000);

nanosleep(&sleep_time, nullptr);
}

CHIP_ERROR TestCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId)
{
ReturnErrorOnFailure(mOpCredsIssuer.Initialize(storage));
Expand All @@ -53,10 +41,6 @@ CHIP_ERROR TestCommand::Run(PersistentStorage & storage, NodeId localId, NodeId

mCommissioner.ServiceEventSignal();

// Give some time for all the pending messages to flush before shutting down
// Note: This is working around racy code in message queues during shutdown
// TODO: Remove this workaround once we understand the message queue and shutdown race
test_os_sleep_ms(1000);
mCommissioner.Shutdown();

VerifyOrReturnError(GetCommandExitStatus(), CHIP_ERROR_INTERNAL);
Expand Down

0 comments on commit 5400379

Please sign in to comment.