1 /* 2 * Copyright (c) 2021 - 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "compileQueue.h" 17 #include "public/public.h" 18 19 namespace ark::es2panda::compiler { 20 Run()21void CompileJob::Run() 22 { 23 std::unique_lock<std::mutex> lock(m_); 24 cond_.wait(lock, [this] { return dependencies_ == 0; }); 25 26 context_->codeGenCb(context_, scope_, &programElement_); 27 28 if (dependant_ != nullptr) { 29 dependant_->Signal(); 30 } 31 } 32 DependsOn(CompileJob * job)33void CompileJob::DependsOn(CompileJob *job) 34 { 35 job->dependant_ = this; 36 dependencies_++; 37 } 38 Signal()39void CompileJob::Signal() 40 { 41 { 42 std::lock_guard<std::mutex> lock(m_); 43 dependencies_--; 44 } 45 46 cond_.notify_one(); 47 } 48 } // namespace ark::es2panda::compiler 49