Improve the locking design inside TrafficController
Rename the mOwnerMatchMutex lock to mMutex and use it to protect all
data structures in TrafficController that could be accessed
concurrently. Add necessary annotations to the data structures needing
protection to catch unsafe access at compile time.
Test: netd_unit_test, netd_integration_test
Bug: 130334320
Change-Id: I847ce518df8626f647e1d80468e4daf4604872f2
diff --git a/server/TrafficControllerTest.cpp b/server/TrafficControllerTest.cpp
index e2a1327..bb56d97 100644
--- a/server/TrafficControllerTest.cpp
+++ b/server/TrafficControllerTest.cpp
@@ -70,7 +70,7 @@
BpfMap<uint32_t, uint8_t> mFakeUidPermissionMap;
void SetUp() {
- std::lock_guard ownerGuard(mTc.mOwnerMatchMutex);
+ std::lock_guard guard(mTc.mMutex);
SKIP_IF_BPF_NOT_SUPPORTED;
ASSERT_EQ(0, setrlimitForTest());
@@ -249,13 +249,17 @@
}
void expectPrivilegedUserSet(const std::vector<uid_t>& appUids) {
+ std::lock_guard guard(mTc.mMutex);
EXPECT_EQ(appUids.size(), mTc.mPrivilegedUser.size());
for (uid_t uid : appUids) {
EXPECT_NE(mTc.mPrivilegedUser.end(), mTc.mPrivilegedUser.find(uid));
}
}
- void expectPrivilegedUserSetEmpty() { EXPECT_TRUE(mTc.mPrivilegedUser.empty()); }
+ void expectPrivilegedUserSetEmpty() {
+ std::lock_guard guard(mTc.mMutex);
+ EXPECT_TRUE(mTc.mPrivilegedUser.empty());
+ }
void addPrivilegedUid(uid_t uid) {
std::vector privilegedUid = {uid};