Remove use of synchronization/lock in tools/gn/import_manager Change-Id: I3d8f4c81db2aec9af16c5b594d849e06e4551b10 Reviewed-on: https://gn-review.googlesource.com/1705 Commit-Queue: Scott Graham <scottmg@chromium.org> Reviewed-by: Brett Wilson <brettw@chromium.org>
diff --git a/tools/gn/import_manager.cc b/tools/gn/import_manager.cc index 405eb01..f4aa32a 100644 --- a/tools/gn/import_manager.cc +++ b/tools/gn/import_manager.cc
@@ -56,7 +56,7 @@ // This lock protects the unique_ptr. Once the scope is computed, // it is const and can be accessed read-only outside of the lock. - base::Lock load_lock; + std::mutex load_lock; std::unique_ptr<const Scope> scope; @@ -82,7 +82,7 @@ // copying outside of the lock. ImportInfo* import_info = nullptr; { - base::AutoLock lock(imports_lock_); + std::lock_guard<std::mutex> lock(imports_lock_); std::unique_ptr<ImportInfo>& info_ptr = imports_[file]; if (!info_ptr) info_ptr = std::make_unique<ImportInfo>(); @@ -102,7 +102,7 @@ const Scope* import_scope = nullptr; { base::TimeTicks import_block_begin = base::TimeTicks::Now(); - base::AutoLock lock(import_info->load_lock); + std::lock_guard<std::mutex> lock(import_info->load_lock); if (!import_info->scope) { // Only load if the import hasn't already failed. @@ -140,7 +140,7 @@ options.mark_dest_used = true; // Don't require all imported values be used. { - base::AutoLock lock(imports_lock_); + std::lock_guard<std::mutex> lock(imports_lock_); imports_in_progress_.erase(key); }
diff --git a/tools/gn/import_manager.h b/tools/gn/import_manager.h index 01d8af6..d72d5a7 100644 --- a/tools/gn/import_manager.h +++ b/tools/gn/import_manager.h
@@ -7,11 +7,12 @@ #include <map> #include <memory> +#include <mutex> +#include <string> #include <unordered_set> #include <vector> #include "base/macros.h" -#include "base/synchronization/lock.h" class Err; class ParseNode; @@ -39,7 +40,7 @@ // Protects access to imports_ and imports_in_progress_. Do not hold when // actually executing imports. - base::Lock imports_lock_; + std::mutex imports_lock_; // Owning pointers to the scopes. typedef std::map<SourceFile, std::unique_ptr<ImportInfo>> ImportMap;
diff --git a/tools/gn/scheduler.cc b/tools/gn/scheduler.cc index 00b5c61..bca1472 100644 --- a/tools/gn/scheduler.cc +++ b/tools/gn/scheduler.cc
@@ -36,7 +36,7 @@ main_thread_run_loop_->Run(); bool local_is_failed; { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); local_is_failed = is_failed(); has_been_shutdown_ = true; } @@ -54,7 +54,7 @@ void Scheduler::FailWithError(const Err& err) { DCHECK(err.has_error()); { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); if (is_failed_ || has_been_shutdown_) return; // Ignore errors once we see one. @@ -81,39 +81,39 @@ } void Scheduler::AddGenDependency(const base::FilePath& file) { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); gen_dependencies_.push_back(file); } std::vector<base::FilePath> Scheduler::GetGenDependencies() const { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); return gen_dependencies_; } void Scheduler::AddWrittenFile(const SourceFile& file) { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); written_files_.push_back(file); } void Scheduler::AddUnknownGeneratedInput(const Target* target, const SourceFile& file) { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); unknown_generated_inputs_.insert(std::make_pair(file, target)); } void Scheduler::AddWriteRuntimeDepsTarget(const Target* target) { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); write_runtime_deps_targets_.push_back(target); } std::vector<const Target*> Scheduler::GetWriteRuntimeDepsTargets() const { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); return write_runtime_deps_targets_; } bool Scheduler::IsFileGeneratedByWriteRuntimeDeps( const OutputFile& file) const { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); // Number of targets should be quite small, so brute-force search is fine. for (const Target* target : write_runtime_deps_targets_) { if (file == target->write_runtime_deps_output()) { @@ -125,7 +125,7 @@ std::multimap<SourceFile, const Target*> Scheduler::GetUnknownGeneratedInputs() const { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); // Remove all unknown inputs that were written files. These are OK as inputs // to build steps since they were written as a side-effect of running GN. @@ -140,7 +140,7 @@ } void Scheduler::ClearUnknownGeneratedInputsAndWrittenFiles() { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); unknown_generated_inputs_.clear(); written_files_.clear(); } @@ -157,7 +157,7 @@ } void Scheduler::SuppressOutputForTesting(bool suppress) { - base::AutoLock lock(lock_); + std::lock_guard<std::mutex> lock(lock_); suppress_output_for_testing_ = suppress; }
diff --git a/tools/gn/scheduler.h b/tools/gn/scheduler.h index 1677b4d..f68a25b 100644 --- a/tools/gn/scheduler.h +++ b/tools/gn/scheduler.h
@@ -125,7 +125,7 @@ WorkerPool worker_pool_; - mutable base::Lock lock_; + mutable std::mutex lock_; bool is_failed_; bool suppress_output_for_testing_;