Protect the construction of the verification thread pool.
Multiple threads may try to allocate it.
Also make the ThreadPool lock a bottom lock.
Test: m
Bug: 172811380
Change-Id: I061e20666cb784feb31be94785f2949451db9de9
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 74fe110..e485413 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -803,16 +803,18 @@
return;
}
- std::string vdex_filename = GetVdexFilename(odex_filename);
- if (verification_thread_pool_ == nullptr) {
- verification_thread_pool_.reset(
- new ThreadPool("Verification thread pool", /* num_threads= */ 1));
- verification_thread_pool_->StartWorkers(self);
+ {
+ WriterMutexLock mu(self, *Locks::oat_file_manager_lock_);
+ if (verification_thread_pool_ == nullptr) {
+ verification_thread_pool_.reset(
+ new ThreadPool("Verification thread pool", /* num_threads= */ 1));
+ verification_thread_pool_->StartWorkers(self);
+ }
}
verification_thread_pool_->AddTask(self, new BackgroundVerificationTask(
dex_files,
class_loader,
- vdex_filename));
+ GetVdexFilename(odex_filename)));
}
void OatFileManager::WaitForWorkersToBeCreated() {
diff --git a/runtime/thread_pool.cc b/runtime/thread_pool.cc
index f991c05..57d7f61 100644
--- a/runtime/thread_pool.cc
+++ b/runtime/thread_pool.cc
@@ -164,7 +164,7 @@
bool create_peers,
size_t worker_stack_size)
: name_(name),
- task_queue_lock_("task queue lock"),
+ task_queue_lock_("task queue lock", kGenericBottomLock),
task_queue_condition_("task queue condition", task_queue_lock_),
completion_condition_("task completion condition", task_queue_lock_),
started_(false),