Skip to content

Commit

Permalink
Make sure that _persistClusterData only notifies delegates when persi…
Browse files Browse the repository at this point in the history
…stence actually happens.
  • Loading branch information
bzbarsky-apple committed Feb 6, 2025
1 parent 129c70c commit 5594ea4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1720,20 +1720,22 @@ - (BOOL)_dataStoreExists
return _persistedClusterData != nil;
}

// Need an inner method for dealloc to call, so unit test callbacks don't re-capture self
- (void)_doPersistClusterData
// Need an inner method for dealloc to call, so unit test callbacks don't re-capture self.
//
// Returns whether persistence actually happened.
- (BOOL)_doPersistClusterData
{
os_unfair_lock_assert_owner(&self->_lock);

// Sanity check
if (![self _dataStoreExists]) {
MTR_LOG_ERROR("%@ storage behavior: no data store in _persistClusterData!", self);
return;
return NO;
}

// Nothing to persist
if (!_clusterDataToPersist.count) {
return;
return NO;
}

MTR_LOG("%@ Storing cluster information (data version and attributes) count: %lu", self, static_cast<unsigned long>(_clusterDataToPersist.count));
Expand All @@ -1757,11 +1759,16 @@ - (void)_doPersistClusterData
// then re-subscribe at that point, which would cause the relevant data
// to be sent to us via the priming read.
_clusterDataToPersist = nil;

return YES;
}

- (void)_persistClusterData
{
[self _doPersistClusterData];
if ([self _doPersistClusterData] == NO) {
// Don't notify delegates if we did not actually persist anything.
return;
}

#ifdef DEBUG
[self _callDelegatesWithBlock:^(id testDelegate) {
Expand Down

0 comments on commit 5594ea4

Please sign in to comment.