• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef PANDA_RUNTIME_COMPILER_QUEUE_SIMPLE_H_
16 #define PANDA_RUNTIME_COMPILER_QUEUE_SIMPLE_H_
17 
18 #include "runtime/compiler_queue_interface.h"
19 #include "runtime/include/mem/panda_containers.h"
20 
21 namespace ark {
22 
23 /**
24  * The simple queue works as FIFO without any other logic: it stores all tasks to a list and extracts the first one.
25  * There is no length limit or expiring condition. Mostly useful for debugging, as is more deterministic.
26  * This queue is thread unsafe (should be used under lock).
27  */
28 class CompilerQueueSimple : public CompilerQueueInterface {
29 public:
CompilerQueueSimple(mem::InternalAllocatorPtr allocator)30     explicit CompilerQueueSimple(mem::InternalAllocatorPtr allocator) : queue_(allocator->Adapter()) {}
31 
GetTask()32     CompilerTask GetTask() override
33     {
34         if (queue_.empty()) {
35             LOG(DEBUG, COMPILATION_QUEUE) << "Empty " << queueName_ << ", return nothing";
36             return CompilerTask();
37         }
38         auto task = std::move(queue_.front());
39         queue_.pop_front();
40         LOG(DEBUG, COMPILATION_QUEUE) << "Extract a task from a " << queueName_ << ": " << GetTaskDescription(task);
41         return task;
42     }
43 
44     // NOLINTNEXTLINE(google-default-arguments)
45     void AddTask(CompilerTask &&ctx, [[maybe_unused]] size_t priority = 0) override
46     {
47         LOG(DEBUG, COMPILATION_QUEUE) << "Add task to a " << queueName_ << ": " << GetTaskDescription(ctx);
48         queue_.push_front(std::move(ctx));
49     }
50 
Finalize()51     void Finalize() override
52     {
53         // Nothing to deallocate
54         LOG(DEBUG, COMPILATION_QUEUE) << "Clear a " << queueName_;
55         queue_.clear();
56     }
57 
58 protected:
GetQueueSize()59     size_t GetQueueSize() override
60     {
61         return queue_.size();
62     }
63 
64 private:
65     PandaList<CompilerTask> queue_;
66     const char *queueName_ = "simple compilation queue";
67 };
68 
69 }  // namespace ark
70 
71 #endif  // PANDA_RUNTIME_COMPILER_QUEUE_H_
72