Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e74205b authored by Tej Singh's avatar Tej Singh
Browse files

Fix thread safety issue on clearing cache

Historically, we havent held a lock on ForceClearCache and
ClearCacheIfNecessary. This is not thread safe because kAllPullAtomInfo
must be accessed in a lock, especially now that pullers can be
registered/unregistered.

Test: atest statsd_test, wrote a repro cl.
Bug: 168156854
Change-Id: I47d53a6d9d274bca4c78dbfd87e0097091b7b8cb
Merged-In: I47d53a6d9d274bca4c78dbfd87e0097091b7b8cb
(cherry picked from commit f9a4bb18)
parent 387efc86
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -334,6 +334,7 @@ void StatsPullerManager::OnAlarmFired(int64_t elapsedTimeNs) {
}

int StatsPullerManager::ForceClearPullerCache() {
    std::lock_guard<std::mutex> _l(mLock);
    int totalCleared = 0;
    for (const auto& pulledAtom : kAllPullAtomInfo) {
        totalCleared += pulledAtom.second->ForceClearCache();
@@ -342,6 +343,7 @@ int StatsPullerManager::ForceClearPullerCache() {
}

int StatsPullerManager::ClearPullerCacheIfNecessary(int64_t timestampNs) {
    std::lock_guard<std::mutex> _l(mLock);
    int totalCleared = 0;
    for (const auto& pulledAtom : kAllPullAtomInfo) {
        totalCleared += pulledAtom.second->ClearCacheIfNecessary(timestampNs);