Skip to content

Commit

Permalink
Assert that controllers are inited and shut down with the Matter lock…
Browse files Browse the repository at this point in the history
… held.

We were not asserting this, and some consumers were not doing this,
leading to data races.
  • Loading branch information
bzbarsky-apple committed Jun 30, 2022
1 parent 31ddf98 commit 8c46799
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include <lib/support/TimeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <messaging/ExchangeContext.h>
#include <platform/LockTracker.h>
#include <protocols/secure_channel/MessageCounterManager.h>
#include <setup_payload/QRCodeSetupPayloadParser.h>
#include <trace/trace.h>
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -282,6 +285,8 @@ CHIP_ERROR DeviceController::InitControllerNOCChain(const ControllerInitParams &

void DeviceController::Shutdown()
{
assertChipStackLockedByCurrentThread();

VerifyOrReturn(mState != State::NotInitialized);

ChipLogDetail(Controller, "Shutting down the controller");
Expand Down

0 comments on commit 8c46799

Please sign in to comment.