• 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 
16 #ifndef PANDA_LIBPANDABASE_TASKMANAGER_SCHEDULABLE_TASK_QUEUE_INTERFACE_H
17 #define PANDA_LIBPANDABASE_TASKMANAGER_SCHEDULABLE_TASK_QUEUE_INTERFACE_H
18 
19 #include "libpandabase/taskmanager/task.h"
20 #include "libpandabase/taskmanager/task_queue_interface.h"
21 #include "libpandabase/taskmanager/utils/task_time_stats.h"
22 
23 namespace ark::taskmanager::internal {
24 
25 class SchedulableTaskQueueInterface : public TaskQueueInterface {
26 public:
27     NO_COPY_SEMANTIC(SchedulableTaskQueueInterface);
28     NO_MOVE_SEMANTIC(SchedulableTaskQueueInterface);
29 
30     /**
31      * NewTasksCallback instance should be called after tasks adding. It should have next arguments:
32      * 1. property of tasks you added
33      * 2. count of tasks you added
34      */
35     using SignalWorkersCallback = std::function<void()>;
36     using SignalWaitersCallback = std::function<void()>;
37 
38     using AddTaskToWorkerFunc = std::function<void(TaskPtr &&)>;
39     using AddTaskToHelperFunc = std::function<void(TaskPtr &&)>;
40 
41     using GetSplittingFactorFunc = std::function<size_t()>;
42 
SchedulableTaskQueueInterface(QueuePriority priority)43     explicit SchedulableTaskQueueInterface(QueuePriority priority) : TaskQueueInterface(priority) {}
44     ~SchedulableTaskQueueInterface() override = default;
45 
46     /// @brief Pops task from queue, return nullptr if it's empty.
47     [[nodiscard]] virtual TaskPtr PopTask() = 0;
48     /// @brief Pops foreground task from queue, return nullptr if no foreground tasks in queue.
49     [[nodiscard]] virtual TaskPtr PopForegroundTask() = 0;
50     /// @brief Pops background task from queue, return nullptr if no background tasks in queue.
51     [[nodiscard]] virtual TaskPtr PopBackgroundTask() = 0;
52 
53     virtual size_t PopTasksToWorker(const AddTaskToWorkerFunc &addFrontendTaskFunc,
54                                     const AddTaskToWorkerFunc &addBackgroundTaskFunc, size_t size) = 0;
55     virtual size_t PopForegroundTasksToHelperThread(const AddTaskToHelperFunc &addTaskFunc, size_t size) = 0;
56     virtual size_t PopBackgroundTasksToHelperThread(const AddTaskToHelperFunc &addTaskFunc, size_t size) = 0;
57 
58     virtual size_t GetCountOfLiveTasks() const = 0;
59     virtual size_t GetCountOfLiveForegroundTasks() const = 0;
60     virtual size_t GetCountOfLiveBackgroundTasks() const = 0;
61 
62     virtual TaskTimeStatsBase *GetTaskTimeStats() const = 0;
63 
64     void virtual SetCallbacks(SignalWorkersCallback signalWorkersCallback) = 0;
65 
66     /// @brief Removes callback function.
67     void virtual UnsetCallbacks() = 0;
68 };
69 
70 }  // namespace ark::taskmanager::internal
71 
72 #endif  // PANDA_LIBPANDABASE_TASKMANAGER_SCHEDULABLE_TASK_QUEUE_INTERFACE_H
73