Skip to content

Commit 15430e7

Browse files
authored
Revert "[Darwin][System] Ensure we do not delete the timer block context twic…" (project-chip#39750)
This reverts commit 2482755.
1 parent 06523c2 commit 15430e7

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

src/platform/Darwin/system/SystemLayerImplDispatch.mm

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ static void TimerCompleteBlockCallback(Layer * aLayer, void * appState)
6060
if (ctx->block) {
6161
ctx->block();
6262
}
63+
delete ctx;
64+
}
65+
66+
void MaybeCancelTimerCompleteBlockCallbackContext(TimerList::Node * timer)
67+
{
68+
VerifyOrReturn(nullptr != timer);
69+
70+
__auto_type & cb = timer->GetCallback();
71+
VerifyOrReturn(cb.GetOnComplete() == TimerCompleteBlockCallback);
72+
73+
__auto_type * ctx = static_cast<TimerCompleteBlockCallbackContext *>(cb.GetAppState());
74+
delete ctx;
6375
}
6476
}
6577

@@ -109,6 +121,7 @@ static void TimerCompleteBlockCallback(Layer * aLayer, void * appState)
109121

110122
TimerList::Node * timer;
111123
while ((timer = mTimerList.PopEarliest()) != nullptr) {
124+
MaybeCancelTimerCompleteBlockCallbackContext(timer);
112125
DisableTimer(__func__, timer);
113126
}
114127
mTimerPool.ReleaseAll();
@@ -203,13 +216,6 @@ static void TimerCompleteBlockCallback(Layer * aLayer, void * appState)
203216
mTimerPool.Invoke(timer);
204217
});
205218

206-
dispatch_source_set_cancel_handler(timerSource, ^{
207-
VerifyOrReturn(onComplete == TimerCompleteBlockCallback);
208-
VerifyOrReturn(nullptr != appState);
209-
210-
__auto_type * ctx = static_cast<TimerCompleteBlockCallbackContext *>(appState);
211-
delete ctx; });
212-
213219
EnableTimer(__func__, timer);
214220
}
215221

@@ -280,6 +286,7 @@ static void TimerCompleteBlockCallback(Layer * aLayer, void * appState)
280286
}
281287
VerifyOrReturn(timer != nullptr);
282288

289+
MaybeCancelTimerCompleteBlockCallbackContext(timer);
283290
DisableTimer(__func__, timer);
284291

285292
mTimerPool.Release(timer);
@@ -317,23 +324,8 @@ static void TimerCompleteBlockCallback(Layer * aLayer, void * appState)
317324
mExpiredTimers = mTimerList.ExtractEarlier(Clock::Timeout(1) + SystemClock().GetMonotonicTimestamp());
318325
TimerList::Node * timer = nullptr;
319326
while ((timer = mExpiredTimers.PopEarliest()) != nullptr) {
320-
TimerCompleteBlockCallbackContext * context = nullptr;
321-
bool shouldDeleteContext = false;
322-
323-
if (!HasTimerSource(timer)) {
324-
__auto_type & cb = timer->GetCallback();
325-
if (cb.GetOnComplete() == TimerCompleteBlockCallback) {
326-
context = static_cast<TimerCompleteBlockCallbackContext *>(cb.GetAppState());
327-
shouldDeleteContext = true;
328-
}
329-
}
330-
331327
DisableTimer(__func__, timer);
332328
mTimerPool.Invoke(timer);
333-
334-
if (shouldDeleteContext) {
335-
delete context;
336-
}
337329
}
338330
#endif
339331
}

0 commit comments

Comments
 (0)