Skip to content

Commit 1866c99

Browse files
committed
Update linked list clearning function
1 parent 4023dd8 commit 1866c99

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/app/server-cluster/ServerClusterInterfaceRegistry.cpp

+21-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@
2424
namespace chip {
2525
namespace app {
2626

27+
namespace {
28+
29+
/// Remove all elements of a linked list rom the linked list.
30+
///
31+
/// Marks every element in the given linked list as not being in a
32+
/// linked list anymore.
33+
void ClearSingleLinkedList(ServerClusterInterface * clusters)
34+
{
35+
while (clusters != nullptr)
36+
{
37+
ServerClusterInterface * next = clusters->GetNextListItem();
38+
clusters->SetNotInList();
39+
clusters = next;
40+
}
41+
}
42+
43+
} // namespace
44+
2745
ServerClusterInterfaceRegistry & ServerClusterInterfaceRegistry::Instance()
2846
{
2947
static ServerClusterInterfaceRegistry sRegistry;
@@ -137,16 +155,6 @@ ServerClusterInterface * ServerClusterInterfaceRegistry::Unregister(const Concre
137155
return nullptr;
138156
}
139157

140-
void ServerClusterInterfaceRegistry::DestroySingleLinkedList(ServerClusterInterface * clusters)
141-
{
142-
while (clusters != nullptr)
143-
{
144-
ServerClusterInterface * next = clusters->GetNextListItem();
145-
clusters->SetNotInList();
146-
clusters = next;
147-
}
148-
}
149-
150158
void ServerClusterInterfaceRegistry::UnregisterAllFromEndpoint(EndpointId endpointId)
151159
{
152160
if ((mEndpointClustersCache != nullptr) && (mEndpointClustersCache->endpointId == endpointId))
@@ -167,7 +175,7 @@ void ServerClusterInterfaceRegistry::UnregisterAllFromEndpoint(EndpointId endpoi
167175
if (ep.endpointId == endpointId)
168176
{
169177
ep.endpointId = kInvalidEndpointId;
170-
DestroySingleLinkedList(ep.firstCluster);
178+
ClearSingleLinkedList(ep.firstCluster);
171179
ep.firstCluster = nullptr;
172180
return;
173181
}
@@ -179,7 +187,7 @@ void ServerClusterInterfaceRegistry::UnregisterAllFromEndpoint(EndpointId endpoi
179187
{
180188
DynamicEndpointClusters * value = mDynamicEndpoints;
181189
mDynamicEndpoints = mDynamicEndpoints->next;
182-
DestroySingleLinkedList(value->firstCluster);
190+
ClearSingleLinkedList(value->firstCluster);
183191
Platform::Delete(value);
184192
return;
185193
}
@@ -191,7 +199,7 @@ void ServerClusterInterfaceRegistry::UnregisterAllFromEndpoint(EndpointId endpoi
191199
if (current->endpointId == endpointId)
192200
{
193201
prev->next = current->next;
194-
DestroySingleLinkedList(current->firstCluster);
202+
ClearSingleLinkedList(current->firstCluster);
195203
Platform::Delete(current);
196204
return;
197205
}

src/app/server-cluster/ServerClusterInterfaceRegistry.h

-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ class ServerClusterInterfaceRegistry
9797

9898
/// Get a new usable (either static or dynamic) endpoint cluster
9999
CHIP_ERROR AllocateNewEndpointClusters(EndpointId endpointId, EndpointClusters *& dest);
100-
101-
// Mark every element in the given list as having no `Next`
102-
void DestroySingleLinkedList(ServerClusterInterface * clusters);
103100
};
104101

105102
} // namespace app

0 commit comments

Comments
 (0)