[compiler-dispatcher] Fix job delete posting

Some bad rebasing meant that we were still deleting on the main thread.

As an additional simplification, remove the specific deletion queue
mutex, and just use the compiler dispatcher mutex for the deletion queue
-- this avoids risks of deadlock when both are held.

Change-Id: Ifa4ead6ee3fd814d7f013dd14a5617456afc9f7f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3328785
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78335}
This commit is contained in:
Leszek Swirski 2021-12-10 09:24:36 +01:00 committed by V8 LUCI CQ
parent 7f121b4f93
commit 2e96d32168
2 changed files with 9 additions and 12 deletions

View File

@ -456,7 +456,7 @@ void LazyCompileDispatcher::DoBackgroundWork(JobDelegate* delegate) {
while (!delegate->ShouldYield()) {
Job* job = nullptr;
{
base::MutexGuard lock(&job_dispose_mutex_);
base::MutexGuard lock(&mutex_);
if (jobs_to_dispose_.empty()) break;
job = jobs_to_dispose_.back();
jobs_to_dispose_.pop_back();
@ -538,13 +538,8 @@ void LazyCompileDispatcher::DoIdleWork(double deadline_in_seconds) {
void LazyCompileDispatcher::DeleteJob(Job* job) {
DCHECK(job->state == Job::State::kFinalized);
#ifdef DEBUG
{
base::MutexGuard lock(&mutex_);
all_jobs_.erase(job);
}
#endif
delete job;
base::MutexGuard lock(&mutex_);
DeleteJob(job, lock);
}
void LazyCompileDispatcher::DeleteJob(Job* job, const base::MutexGuard&) {
@ -552,7 +547,6 @@ void LazyCompileDispatcher::DeleteJob(Job* job, const base::MutexGuard&) {
#ifdef DEBUG
all_jobs_.erase(job);
#endif
base::MutexGuard lock(&job_dispose_mutex_);
jobs_to_dispose_.push_back(job);
if (jobs_to_dispose_.size() == 1) {
num_jobs_for_background_++;

View File

@ -220,14 +220,17 @@ class V8_EXPORT_PRIVATE LazyCompileDispatcher {
std::unordered_set<Job*> all_jobs_;
#endif
// A queue of jobs to delete on the background thread(s). Jobs in this queue
// are considered dead as far as the rest of the system is concerned, so they
// won't be pointed to by any SharedFunctionInfo and won't be in the all_jobs
// set above.
std::vector<Job*> jobs_to_dispose_;
// If not nullptr, then the main thread waits for the task processing
// this job, and blocks on the ConditionVariable main_thread_blocking_signal_.
Job* main_thread_blocking_on_job_;
base::ConditionVariable main_thread_blocking_signal_;
mutable base::Mutex job_dispose_mutex_;
std::vector<Job*> jobs_to_dispose_;
// Test support.
base::AtomicValue<bool> block_for_testing_;
base::Semaphore semaphore_for_testing_;