Add NamedLatch to statsd
This is a sychronizing primitive that is similar to a latch, but a
thread must count down with an identifier. It will be used to make sure
the boot complete, uid map, and all pullers signals are received before
triggering the bucket split.
The latch's countDown operation takes in a string identifier, so that if
the same operation happens twice, it is only counted once.
Bug: 144099206
Test: atest statsd_test
Change-Id: I261a3e50eabbc4998ca30ddf2d67a9a1e788911e
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index dd1d400..ae7a8d0 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -118,8 +118,9 @@
}
})),
mEventQueue(queue),
- mStatsCompanionServiceDeathRecipient(AIBinder_DeathRecipient_new(
- StatsService::statsCompanionServiceDied)) {
+ mBootCompleteLatch({kBootCompleteTag, kUidMapReceivedTag, kAllPullersRegisteredTag}),
+ mStatsCompanionServiceDeathRecipient(
+ AIBinder_DeathRecipient_new(StatsService::statsCompanionServiceDied)) {
mUidMap = UidMap::getInstance();
mPullerManager = new StatsPullerManager();
StatsPuller::SetUidMap(mUidMap);
@@ -164,6 +165,12 @@
std::thread pushedEventThread([this] { readLogs(); });
pushedEventThread.detach();
}
+
+ std::thread bootCompletedThread([this] {
+ mBootCompleteLatch.wait();
+ VLOG("In the boot completed thread");
+ });
+ bootCompletedThread.detach();
}
StatsService::~StatsService() {
@@ -939,6 +946,7 @@
packageNames,
installers);
+ mBootCompleteLatch.countDown(kUidMapReceivedTag);
VLOG("StatsService::informAllUidData UidData proto parsed successfully.");
return Status::ok();
}
@@ -1058,7 +1066,7 @@
ENFORCE_UID(AID_SYSTEM);
VLOG("StatsService::bootCompleted was called");
-
+ mBootCompleteLatch.countDown(kBootCompleteTag);
return Status::ok();
}
@@ -1227,7 +1235,7 @@
ENFORCE_UID(AID_SYSTEM);
VLOG("StatsService::allPullersFromBootRegistered was called");
-
+ mBootCompleteLatch.countDown(kAllPullersRegisteredTag);
return Status::ok();
}