diff --git a/es2panda/aot/emitFiles.cpp b/es2panda/aot/emitFiles.cpp index 462708ae154de485035f100c6a789f68aab4c18d..9cf757083ad48cd11ae87f688dbff2e1ff6b02f6 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 d475dacc81912f07b9bd24913f5c862b167cf89d..b35a7c0c174930717058e672b1833fc121346627 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 ed4d8dbc95fd584532f87b81b280382fed307192..24061b69a15dc3e727d80fe4a0f0e622ae68ebd3 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 7b38f6419f7c09d7a1a2c123652f39cb0ff070cf..22fa97a83b5a8e6b7eafdee5e782ecf8997e432a 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}; };