Skip to content

Commit

Permalink
Best-effort flush events at shutdown (#15331)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Jan 18, 2024
1 parent b366707 commit 1239728
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/reporting/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ CHIP_ERROR Engine::Init()

void Engine::Shutdown()
{
// Flush out the event buffer synchronously
ScheduleUrgentEventDeliverySync();

mNumReportsInFlight = 0;
mCurReadHandlerIdx = 0;
mGlobalDirtySet.ReleaseAll();
Expand Down Expand Up @@ -746,6 +749,22 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, EventOptions
return CHIP_NO_ERROR;
}

void Engine::ScheduleUrgentEventDeliverySync()
{
InteractionModelEngine::GetInstance()->mReadHandlers.ForEachActiveObject([](ReadHandler * handler) {
if (handler->IsType(ReadHandler::InteractionType::Read))
{
return Loop::Continue;
}

handler->UnblockUrgentEventDelivery();

return Loop::Continue;
});

Run();
}

}; // namespace reporting
} // namespace app
} // namespace chip
Expand Down
1 change: 1 addition & 0 deletions src/app/reporting/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class Engine
CHIP_ERROR ScheduleUrgentEventDelivery(ConcreteEventPath & aPath);
CHIP_ERROR ScheduleBufferPressureEventDelivery(uint32_t aBytesWritten);
void GetMinEventLogPosition(uint32_t & aMinLogPosition);
void ScheduleUrgentEventDeliverySync();

/**
* If the provided path is a superset of our of our existing paths, update that existing path to match the
Expand Down

0 comments on commit 1239728

Please sign in to comment.