From ea17f3e7cf30681768ecfa2ab3dd78392ad1b3b0 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Thu, 27 Jul 2023 09:51:07 +0800 Subject: [PATCH] Fix occasionally imcomplete content for protoBin file Issue:I7NL79 Signed-off-by: gavin1012_hw Change-Id: I582e0900c1ed1292f055835039f6b98de260f39f --- es2panda/aot/emitFiles.cpp | 37 +++++++++++++++---------- es2panda/compiler/core/compileQueue.cpp | 8 +++--- es2panda/util/workerQueue.cpp | 6 ++-- es2panda/util/workerQueue.h | 2 +- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/es2panda/aot/emitFiles.cpp b/es2panda/aot/emitFiles.cpp index 462708ae15..9cf757083a 100644 --- a/es2panda/aot/emitFiles.cpp +++ b/es2panda/aot/emitFiles.cpp @@ -26,14 +26,28 @@ void EmitFileQueue::Schedule() ASSERT(jobsCount_ == 0); std::unique_lock lock(m_); - // generate abcs if (mergeAbc_) { + // generate merged abc auto emitMergedAbcJob = new EmitMergedAbcJob(options_->CompilerOutput(), progsInfo_); jobs_.push_back(emitMergedAbcJob); jobsCount_++; + for (const auto &info: progsInfo_) { + // generate cache protoBins and set dependencies + if (!info.second->needUpdateCache) { + continue; + } + auto outputCacheIter = options_->CompilerOptions().cacheFiles.find(info.first); + if (outputCacheIter != options_->CompilerOptions().cacheFiles.end()) { + auto emitProtoJob = new EmitCacheJob(outputCacheIter->second, info.second); + emitProtoJob->DependsOn(emitMergedAbcJob); + jobs_.push_back(emitProtoJob); + jobsCount_++; + } + } } else { for (const auto &info: progsInfo_) { try { + // generate multi abcs auto outputFileName = options_->OutputFiles().empty() ? options_->CompilerOutput() : options_->OutputFiles().at(info.first); auto emitSingleAbcJob = new EmitSingleAbcJob(outputFileName, &(info.second->program), statp_); @@ -45,19 +59,6 @@ void EmitFileQueue::Schedule() } } - // generate cache protoBins - for (const auto &info: progsInfo_) { - if (!info.second->needUpdateCache) { - continue; - } - auto outputCacheIter = options_->CompilerOptions().cacheFiles.find(info.first); - if (outputCacheIter != options_->CompilerOptions().cacheFiles.end()) { - auto emitProtoJob = new EmitCacheJob(outputCacheIter->second, info.second); - jobs_.push_back(emitProtoJob); - jobsCount_++; - } - } - lock.unlock(); jobsAvailable_.notify_all(); } @@ -69,6 +70,9 @@ void EmitSingleAbcJob::Run() throw Error(ErrorType::GENERIC, "Failed to emit " + outputFileName_ + ", error: " + panda::pandasm::AsmEmitter::GetLastError()); } + for (auto *dependant : dependants_) { + dependant->Signal(); + } } void EmitMergedAbcJob::Run() @@ -83,10 +87,15 @@ void EmitMergedAbcJob::Run() throw Error(ErrorType::GENERIC, "Failed to emit " + outputFileName_ + ", error: " + panda::pandasm::AsmEmitter::GetLastError()); } + for (auto *dependant : dependants_) { + dependant->Signal(); + } } void EmitCacheJob::Run() { + std::unique_lock lock(m_); + cond_.wait(lock, [this] { return dependencies_ == 0; }); panda::proto::ProtobufSnapshotGenerator::UpdateCacheFile(progCache_, outputProtoName_); } diff --git a/es2panda/compiler/core/compileQueue.cpp b/es2panda/compiler/core/compileQueue.cpp index d475dacc81..b35a7c0c17 100644 --- a/es2panda/compiler/core/compileQueue.cpp +++ b/es2panda/compiler/core/compileQueue.cpp @@ -47,8 +47,8 @@ void CompileFunctionJob::Run() context_->GetEmitter()->AddFunction(&funcEmitter, context_); - if (dependant_) { - dependant_->Signal(); + for (auto *dependant : dependants_) { + dependant->Signal(); } } @@ -62,8 +62,8 @@ void CompileModuleRecordJob::Run() context_->GetEmitter()->AddSourceTextModuleRecord(&moduleEmitter, context_); - if (dependant_) { - dependant_->Signal(); + for (auto *dependant : dependants_) { + dependant->Signal(); } } diff --git a/es2panda/util/workerQueue.cpp b/es2panda/util/workerQueue.cpp index ed4d8dbc95..24061b69a1 100644 --- a/es2panda/util/workerQueue.cpp +++ b/es2panda/util/workerQueue.cpp @@ -19,7 +19,7 @@ namespace panda::es2panda::util { void WorkerJob::DependsOn(WorkerJob *job) { - job->dependant_ = this; + job->dependants_.push_back(this); dependencies_++; } @@ -79,8 +79,8 @@ void WorkerQueue::Consume() activeWorkers_++; while (jobsCount_ > 0) { - --jobsCount_; - auto &job = *(jobs_[jobsCount_]); + auto &job = *(jobs_[jobs_.size() - jobsCount_]); + jobsCount_--; lock.unlock(); diff --git a/es2panda/util/workerQueue.h b/es2panda/util/workerQueue.h index 7b38f6419f..22fa97a83b 100644 --- a/es2panda/util/workerQueue.h +++ b/es2panda/util/workerQueue.h @@ -39,7 +39,7 @@ public: protected: std::mutex m_; std::condition_variable cond_; - WorkerJob *dependant_ {}; + std::vector dependants_ {}; size_t dependencies_ {0}; }; -- Gitee