Remove use of synchronization/lock in tools/gn/input_file_manager

Change-Id: I7c24dffb23bb17eddb633bd76341fbea3c21934a
Reviewed-on: https://gn-review.googlesource.com/1704
Reviewed-by: Brett Wilson <brettw@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/tools/gn/input_file_manager.cc b/tools/gn/input_file_manager.cc
index 5ac71f0..9fba45f 100644
--- a/tools/gn/input_file_manager.cc
+++ b/tools/gn/input_file_manager.cc
@@ -18,6 +18,17 @@
 
 namespace {
 
+// The opposite of std::lock_guard.
+struct ScopedUnlock {
+  ScopedUnlock(std::unique_lock<std::mutex>& lock) : lock_(lock) {
+    lock_.unlock();
+  }
+  ~ScopedUnlock() { lock_.lock(); }
+
+ private:
+  std::unique_lock<std::mutex>& lock_;
+};
+
 void InvokeFileLoadCallback(const InputFileManager::FileLoadCallback& cb,
                             const ParseNode* node) {
   cb.Run(node);
@@ -102,7 +113,7 @@
   // after we leave the lock.
   Task schedule_this;
   {
-    base::AutoLock lock(lock_);
+    std::lock_guard<std::mutex> lock(lock_);
 
     InputFileMap::const_iterator found = input_files_.find(file_name);
     if (found == input_files_.end()) {
@@ -153,7 +164,7 @@
     const BuildSettings* build_settings,
     const SourceFile& file_name,
     Err* err) {
-  base::AutoLock lock(lock_);
+  std::unique_lock<std::mutex> lock(lock_);
 
   InputFileData* data = nullptr;
   InputFileMap::iterator found = input_files_.find(file_name);
@@ -165,7 +176,7 @@
     data->sync_invocation = true;
     input_files_[file_name] = std::move(new_data);
 
-    base::AutoUnlock unlock(lock_);
+    ScopedUnlock unlock(lock);
     if (!LoadFile(origin, build_settings, file_name, &data->file, err))
       return nullptr;
   } else {
@@ -208,7 +219,7 @@
             base::WaitableEvent::InitialState::NOT_SIGNALED);
       }
       {
-        base::AutoUnlock unlock(lock_);
+        ScopedUnlock unlock(lock);
         data->completion_event->Wait();
       }
       // If there were multiple waiters on the same event, we now need to wake
@@ -236,19 +247,19 @@
   *tokens = &data->tokens;
   *parse_root = &data->parsed_root;
   {
-    base::AutoLock lock(lock_);
+    std::lock_guard<std::mutex> lock(lock_);
     dynamic_inputs_.push_back(std::move(data));
   }
 }
 
 int InputFileManager::GetInputFileCount() const {
-  base::AutoLock lock(lock_);
+  std::lock_guard<std::mutex> lock(lock_);
   return static_cast<int>(input_files_.size());
 }
 
 void InputFileManager::GetAllPhysicalInputFileNames(
     std::vector<base::FilePath>* result) const {
-  base::AutoLock lock(lock_);
+  std::lock_guard<std::mutex> lock(lock_);
   result->reserve(input_files_.size());
   for (const auto& file : input_files_) {
     if (!file.second->file.physical_name().empty())
@@ -283,7 +294,7 @@
 
   std::vector<FileLoadCallback> callbacks;
   {
-    base::AutoLock lock(lock_);
+    std::lock_guard<std::mutex> lock(lock_);
     DCHECK(input_files_.find(name) != input_files_.end());
 
     InputFileData* data = input_files_[name].get();
diff --git a/tools/gn/input_file_manager.h b/tools/gn/input_file_manager.h
index f4dc130..ea29651 100644
--- a/tools/gn/input_file_manager.h
+++ b/tools/gn/input_file_manager.h
@@ -5,6 +5,7 @@
 #ifndef TOOLS_GN_INPUT_FILE_MANAGER_H_
 #define TOOLS_GN_INPUT_FILE_MANAGER_H_
 
+#include <mutex>
 #include <set>
 #include <unordered_map>
 #include <utility>
@@ -14,7 +15,6 @@
 #include "base/files/file_path.h"
 #include "base/macros.h"
 #include "base/memory/ref_counted.h"
-#include "base/synchronization/lock.h"
 #include "base/synchronization/waitable_event.h"
 #include "tools/gn/build_settings.h"
 #include "tools/gn/input_file.h"
@@ -134,7 +134,7 @@
                 InputFile* file,
                 Err* err);
 
-  mutable base::Lock lock_;
+  mutable std::mutex lock_;
 
   // Maps repo-relative filenames to the corresponding owned pointer.
   typedef std::unordered_map<SourceFile, std::unique_ptr<InputFileData>>