File tree 3 files changed +13
-5
lines changed
3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,8 @@ CHIP_ERROR DeviceControllerFactory::Init(FactoryInitParams params)
68
68
mSessionResumptionStorage = params.sessionResumptionStorage ;
69
69
mEnableServerInteractions = params.enableServerInteractions ;
70
70
71
+ // Initialize the system state. Note that it is left in a somewhat
72
+ // special state where it is initialized, but has a ref count of 0.
71
73
CHIP_ERROR err = InitSystemState (params);
72
74
73
75
return err;
@@ -76,7 +78,7 @@ CHIP_ERROR DeviceControllerFactory::Init(FactoryInitParams params)
76
78
CHIP_ERROR DeviceControllerFactory::ReinitSystemStateIfNecessary ()
77
79
{
78
80
VerifyOrReturnError (mSystemState != nullptr , CHIP_ERROR_INCORRECT_STATE);
79
- VerifyOrReturnError (mSystemState ->IsShutdown (), CHIP_NO_ERROR);
81
+ VerifyOrReturnError (mSystemState ->IsShutDown (), CHIP_NO_ERROR);
80
82
81
83
FactoryInitParams params;
82
84
params.systemLayer = mSystemState ->SystemLayer ();
@@ -404,6 +406,8 @@ void DeviceControllerFactory::Shutdown()
404
406
{
405
407
if (mSystemState != nullptr )
406
408
{
409
+ // ~DeviceControllerSystemState will call Shutdown(),
410
+ // which in turn ensures that the reference count is 0.
407
411
Platform::Delete (mSystemState );
408
412
mSystemState = nullptr ;
409
413
}
Original file line number Diff line number Diff line change @@ -172,7 +172,9 @@ class DeviceControllerFactory
172
172
173
173
// Shuts down matter and frees the system state.
174
174
//
175
- // Must not be called while any controllers are alive.
175
+ // Must not be called while any controllers are alive, or while any calls
176
+ // to RetainSystemState or EnsureAndRetainSystemState have not been balanced
177
+ // by a call to ReleaseSystemState.
176
178
void Shutdown ();
177
179
178
180
CHIP_ERROR SetupController (SetupParams params, DeviceController & controller);
@@ -195,7 +197,8 @@ class DeviceControllerFactory
195
197
// all device controllers have ceased to exist. To avoid that, this method has been
196
198
// created to permit retention of the underlying system state.
197
199
//
198
- // NB: The system state will still be freed in Shutdown() regardless of this call.
200
+ // Calls to this method must be balanced by calling ReleaseSystemState before Shutdown.
201
+ //
199
202
void RetainSystemState ();
200
203
201
204
//
@@ -210,6 +213,7 @@ class DeviceControllerFactory
210
213
bool ReleaseSystemState ();
211
214
212
215
// Like RetainSystemState(), but will re-initialize the system state first if necessary.
216
+ // Calls to this method must be balanced by calling ReleaseSystemState before Shutdown.
213
217
CHIP_ERROR EnsureAndRetainSystemState ();
214
218
215
219
//
Original file line number Diff line number Diff line change @@ -169,7 +169,7 @@ class DeviceControllerSystemState
169
169
{
170
170
auto count = mRefCount ++;
171
171
VerifyOrDie (count < std::numeric_limits<decltype (count)>::max ()); // overflow
172
- VerifyOrDie (!IsShutdown ()); // avoid zombie
172
+ VerifyOrDie (!IsShutDown ()); // avoid zombie
173
173
return this ;
174
174
};
175
175
@@ -197,7 +197,7 @@ class DeviceControllerSystemState
197
197
mGroupDataProvider != nullptr && mReportScheduler != nullptr && mTimerDelegate != nullptr &&
198
198
mSessionKeystore != nullptr && mSessionResumptionStorage != nullptr && mBDXTransferServer != nullptr ;
199
199
};
200
- bool IsShutdown () { return mHaveShutDown ; }
200
+ bool IsShutDown () { return mHaveShutDown ; }
201
201
202
202
System::Layer * SystemLayer () const { return mSystemLayer ; };
203
203
Inet::EndPointManager<Inet::TCPEndPoint> * TCPEndPointManager () const { return mTCPEndPointManager ; };
You can’t perform that action at this time.
0 commit comments