• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 RUTNIME_COMPILER_TASK_MANAGER_WORKER_H
16 #define RUTNIME_COMPILER_TASK_MANAGER_WORKER_H
17 
18 #include "runtime/compiler_worker.h"
19 #include "runtime/include/runtime.h"
20 #include "runtime/include/mem/panda_containers.h"
21 #include "libpandabase/taskmanager/task.h"
22 #include "libpandabase/taskmanager/task_queue.h"
23 #include "libpandabase/taskmanager/task_manager.h"
24 
25 namespace ark {
26 
27 /// @brief Compiler worker task pool based on common TaskManager (TaskQueue)
28 class CompilerTaskManagerWorker : public CompilerWorker {
29 public:
30     CompilerTaskManagerWorker(mem::InternalAllocatorPtr internalAllocator, Compiler *compiler);
31 
32     NO_COPY_SEMANTIC(CompilerTaskManagerWorker);
33     NO_MOVE_SEMANTIC(CompilerTaskManagerWorker);
34 
InitializeWorker()35     void InitializeWorker() override
36     {
37         compilerWorkerJoined_ = false;
38     }
39 
FinalizeWorker()40     void FinalizeWorker() override
41     {
42         JoinWorker();
43     }
44 
45     void JoinWorker() override;
46 
IsWorkerJoined()47     bool IsWorkerJoined() override
48     {
49         return compilerWorkerJoined_;
50     }
51 
52     void AddTask(CompilerTask &&task) override;
53 
~CompilerTaskManagerWorker()54     ~CompilerTaskManagerWorker() override
55     {
56         taskmanager::TaskManager::DestroyTaskQueue<decltype(internalAllocator_->Adapter())>(compilerTaskManagerQueue_);
57     }
58 
59 private:
60     void BackgroundCompileMethod(CompilerTask &&ctx);
61 
62     taskmanager::TaskQueueInterface *compilerTaskManagerQueue_ {nullptr};
63     os::memory::Mutex taskQueueLock_;
64     // This queue is used for methods need to be compiled inside TaskScheduler without compilation_lock_.
65     PandaDeque<CompilerTask> compilerTaskDeque_ GUARDED_BY(taskQueueLock_);
66     std::atomic<bool> compilerWorkerJoined_ {true};
67 };
68 
69 }  // namespace ark
70 
71 #endif  // RUTNIME_COMPILER_TASK_MANAGER_WORKER_H
72