libperfmgr: Reuse lock in NodeLooperThread

HintManager is thread-safe as it only read maps and use NodeLooperThread
to do hint and cancel.

Test: libperfmgr_test

(cherry picked from commit 8f5e70d4ccfcc17ab9e56a8d94000f0cbb43f8e0)

Change-Id: If4669dffc6c20e0bbb6861ccf59e9fe21893379d
diff --git a/libperfmgr/HintManager.cc b/libperfmgr/HintManager.cc
index 9d70e23..2444c7c 100644
--- a/libperfmgr/HintManager.cc
+++ b/libperfmgr/HintManager.cc
@@ -40,22 +40,20 @@
 }
 
 bool HintManager::DoHint(const std::string& hint_type) {
-    std::lock_guard<std::mutex> lk(lock_);
     LOG(VERBOSE) << "Do Powerhint: " << hint_type;
     return ValidateHint(hint_type)
-               ? nm_->Request(actions_[hint_type], hint_type)
+               ? nm_->Request(actions_.at(hint_type), hint_type)
                : false;
 }
 
 bool HintManager::DoHint(const std::string& hint_type,
                          std::chrono::milliseconds timeout_ms_override) {
-    std::lock_guard<std::mutex> lk(lock_);
     LOG(VERBOSE) << "Do Powerhint: " << hint_type << " for "
                  << timeout_ms_override.count() << "ms";
     if (!ValidateHint(hint_type)) {
         return false;
     }
-    std::vector<NodeAction> actions_override = actions_[hint_type];
+    std::vector<NodeAction> actions_override = actions_.at(hint_type);
     for (auto& action : actions_override) {
         action.timeout_ms = timeout_ms_override;
     }
@@ -63,10 +61,10 @@
 }
 
 bool HintManager::EndHint(const std::string& hint_type) {
-    std::lock_guard<std::mutex> lk(lock_);
     LOG(VERBOSE) << "End Powerhint: " << hint_type;
-    return ValidateHint(hint_type) ? nm_->Cancel(actions_[hint_type], hint_type)
-                                   : false;
+    return ValidateHint(hint_type)
+               ? nm_->Cancel(actions_.at(hint_type), hint_type)
+               : false;
 }
 
 bool HintManager::IsRunning() const {
diff --git a/libperfmgr/include/perfmgr/HintManager.h b/libperfmgr/include/perfmgr/HintManager.h
index 65a8e77..5590a28 100644
--- a/libperfmgr/include/perfmgr/HintManager.h
+++ b/libperfmgr/include/perfmgr/HintManager.h
@@ -18,7 +18,6 @@
 #define ANDROID_LIBPERFMGR_HINTMANAGER_H_
 
 #include <cstddef>
-#include <mutex>
 #include <string>
 #include <vector>
 
@@ -34,7 +33,7 @@
 class HintManager {
   public:
     HintManager(sp<NodeLooperThread> nm,
-                std::map<std::string, std::vector<NodeAction>> actions)
+                const std::map<std::string, std::vector<NodeAction>>& actions)
         : nm_(std::move(nm)), actions_(actions) {}
     ~HintManager() {
         if (nm_.get() != nullptr) nm_->Stop();
@@ -75,8 +74,7 @@
     bool ValidateHint(const std::string& hint_type) const;
 
     sp<NodeLooperThread> nm_;
-    std::map<std::string, std::vector<NodeAction>> actions_;
-    std::mutex lock_;
+    const std::map<std::string, std::vector<NodeAction>> actions_;
 };
 
 }  // namespace perfmgr