1 /** 2 * Copyright (c) 2023-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 #ifndef PANDA_RUNTIME_COMPILER_WORKER_H 16 #define PANDA_RUNTIME_COMPILER_WORKER_H 17 18 #include "libpandabase/macros.h" 19 #include "libpandabase/os/mutex.h" 20 #include "runtime/include/mem/allocator.h" 21 #include "runtime/include/compiler_interface.h" 22 23 namespace ark { 24 25 class Compiler; 26 27 /// @brief Compiler worker interface 28 class CompilerWorker { 29 public: CompilerWorker(mem::InternalAllocatorPtr internalAllocator,Compiler * compiler)30 CompilerWorker(mem::InternalAllocatorPtr internalAllocator, Compiler *compiler) 31 : internalAllocator_(internalAllocator), compiler_(compiler) 32 { 33 } 34 35 NO_COPY_SEMANTIC(CompilerWorker); 36 NO_MOVE_SEMANTIC(CompilerWorker); 37 38 virtual ~CompilerWorker() = default; 39 40 /** 41 * @brief Initializes the compiler worker. 42 * After that, you can start to add tasks to the compiler worker 43 */ 44 virtual void InitializeWorker() = 0; 45 46 /** 47 * @brief Finalizes the compiler worker. 48 * After that, task queue is empty and you must not call the AddTask method 49 */ 50 virtual void FinalizeWorker() = 0; 51 52 /** 53 * @brief Atomically closes the worker task queue 54 * and waiting for all tasks from the queue to be processed. 55 * This method is thread-safe with respect to the AddTask method 56 */ 57 virtual void JoinWorker() = 0; 58 59 /** 60 * @brief Returns state of the compiler worker 61 * @return true if task queue is closed or 62 * the worker is not initialized, false - otherwise 63 */ 64 virtual bool IsWorkerJoined() = 0; 65 66 /** 67 * @brief Adds task in the compiler worker task queue. 68 * This method should be used after InitializeWorker and 69 * it has no effect after JoinWorker. 70 */ 71 virtual void AddTask(CompilerTask &&task) = 0; 72 73 protected: 74 mem::InternalAllocatorPtr internalAllocator_; // NOLINT(misc-non-private-member-variables-in-classes) 75 Compiler *compiler_; // NOLINT(misc-non-private-member-variables-in-classes) 76 }; 77 78 } // namespace ark 79 80 #endif // PANDA_RUNTIME_COMPILER_WORKER_H 81