Refine lock of RouteController and add annotations
Test: built, flashed, booted
system/netd/tests/runtests.sh passes
Change-Id: I855e044a2b7c9aae795edbcee717d61f58a7a21d
diff --git a/server/RouteController.cpp b/server/RouteController.cpp
index ccec437..cdf3c80 100644
--- a/server/RouteController.cpp
+++ b/server/RouteController.cpp
@@ -155,7 +155,7 @@
}
uint32_t RouteController::getIfIndex(const char* interface) {
- std::shared_lock<std::shared_mutex> lock(sInterfaceToTableLock);
+ std::lock_guard<std::mutex> lock(sInterfaceToTableLock);
auto iter = sInterfaceToTable.find(interface);
if (iter == sInterfaceToTable.end()) {
@@ -167,7 +167,7 @@
}
uint32_t RouteController::getRouteTableForInterface(const char* interface) {
- std::shared_lock<std::shared_mutex> lock(sInterfaceToTableLock);
+ std::lock_guard<std::mutex> lock(sInterfaceToTableLock);
return getRouteTableForInterfaceLocked(interface);
}
@@ -191,7 +191,7 @@
addTableName(ROUTE_TABLE_LEGACY_NETWORK, ROUTE_TABLE_NAME_LEGACY_NETWORK, &contents);
addTableName(ROUTE_TABLE_LEGACY_SYSTEM, ROUTE_TABLE_NAME_LEGACY_SYSTEM, &contents);
- std::shared_lock<std::shared_mutex> lock(sInterfaceToTableLock);
+ std::lock_guard<std::mutex> lock(sInterfaceToTableLock);
for (const auto& entry : sInterfaceToTable) {
addTableName(entry.second, entry.first, &contents);
}
@@ -927,7 +927,7 @@
// Returns 0 on success or negative errno on failure.
WARN_UNUSED_RESULT int RouteController::flushRoutes(const char* interface) {
- std::lock_guard<std::shared_mutex> lock(sInterfaceToTableLock);
+ std::lock_guard<std::mutex> lock(sInterfaceToTableLock);
uint32_t table = getRouteTableForInterfaceLocked(interface);
if (table == RT_TABLE_UNSPEC) {
@@ -1089,7 +1089,7 @@
}
// Protects sInterfaceToTable.
-std::shared_mutex RouteController::sInterfaceToTableLock;
+std::mutex RouteController::sInterfaceToTableLock;
std::map<std::string, uint32_t> RouteController::sInterfaceToTable;