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.h b/server/RouteController.h
index 57920d6..d40288b 100644
--- a/server/RouteController.h
+++ b/server/RouteController.h
@@ -20,10 +20,12 @@
 #include "NetdConstants.h"
 #include "Permission.h"
 
+#include <android-base/thread_annotations.h>
+
 #include <linux/netlink.h>
 #include <sys/types.h>
 #include <map>
-#include <shared_mutex>
+#include <mutex>
 
 namespace android {
 namespace net {
@@ -53,7 +55,7 @@
     // correspond to different interface indices over time. This way, even if the interface
     // index has changed, we can still free any map entries indexed by the ifindex that was
     // used to add them.
-    static uint32_t getIfIndex(const char* interface);
+    static uint32_t getIfIndex(const char* interface) EXCLUDES(sInterfaceToTableLock);
 
     static int addInterfaceToLocalNetwork(unsigned netId, const char* interface) WARN_UNUSED_RESULT;
     static int removeInterfaceFromLocalNetwork(unsigned netId,
@@ -111,15 +113,16 @@
 
 private:
     friend class RouteControllerTest;
-    // Protects access to interfaceToTable.
-    static std::shared_mutex sInterfaceToTableLock;
-    static std::map<std::string, uint32_t> sInterfaceToTable;
+
+    static std::mutex sInterfaceToTableLock;
+    static std::map<std::string, uint32_t> sInterfaceToTable GUARDED_BY(sInterfaceToTableLock);
 
     static int configureDummyNetwork();
-    static int flushRoutes(const char* interface);
+    static int flushRoutes(const char* interface) EXCLUDES(sInterfaceToTableLock);
     static int flushRoutes(uint32_t table);
-    static uint32_t getRouteTableForInterfaceLocked(const char *interface);
-    static uint32_t getRouteTableForInterface(const char *interface);
+    static uint32_t getRouteTableForInterfaceLocked(const char *interface)
+            REQUIRES(sInterfaceToTableLock);
+    static uint32_t getRouteTableForInterface(const char *interface) EXCLUDES(sInterfaceToTableLock);
     static int modifyDefaultNetwork(uint16_t action, const char* interface, Permission permission);
     static int modifyPhysicalNetwork(unsigned netId, const char* interface, Permission permission,
                                      bool add);
@@ -132,7 +135,7 @@
     static int modifyVirtualNetwork(unsigned netId, const char* interface,
                                     const UidRanges& uidRanges, bool secure, bool add,
                                     bool modifyNonUidBasedRules);
-    static void updateTableNamesFile();
+    static void updateTableNamesFile() EXCLUDES(sInterfaceToTableLock);
 };
 
 // Public because they are called by by RouteControllerTest.cpp.