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