1 /* 2 * Copyright (c) 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 LIBPANDABASE_TASKMANAGER_TASK_MANAGER_COMMON_H 17 #define LIBPANDABASE_TASKMANAGER_TASK_MANAGER_COMMON_H 18 19 #include <cstdint> 20 #include <functional> 21 22 #include "libpandabase/macros.h" 23 #include "libpandabase/taskmanager/utils/wait_list.h" 24 25 namespace ark::taskmanager { 26 27 // Priority of queue 28 using QueuePriority = uint8_t; 29 static constexpr QueuePriority MAX_QUEUE_PRIORITY = 16U; 30 static constexpr QueuePriority MIN_QUEUE_PRIORITY = 1U; 31 static constexpr QueuePriority DEFAULT_QUEUE_PRIORITY = 4U; 32 33 // CC-OFFNXT(G.PRE.02-CPP): code generation 34 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 35 #define TASK_MANAGER_CHECK_PRIORITY_VALUE(priority) \ 36 ASSERT((priority) <= ::ark::taskmanager::MAX_QUEUE_PRIORITY); \ 37 ASSERT((priority) >= ::ark::taskmanager::MIN_QUEUE_PRIORITY) 38 39 // Queue id 40 using QueueId = size_t; 41 static constexpr QueueId MAX_ID_COUNT = 32U; 42 static constexpr QueueId INVALID_ID = MAX_ID_COUNT; 43 static constexpr size_t MAX_COUNT_OF_QUEUE = MAX_ID_COUNT; 44 45 // CC-OFFNXT(G.PRE.02-CPP): code generation 46 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 47 #define TASK_MANAGER_CHECK_ID_VALUE(id) ASSERT((id) < ::ark::taskmanager::MAX_ID_COUNT) 48 49 using RunnerCallback = std::function<void()>; 50 51 static constexpr size_t MAX_WORKER_COUNT = 16U; 52 53 using TaskWaitListElem = std::pair<RunnerCallback, std::function<void(RunnerCallback)>>; 54 using TaskWaitList = WaitList<TaskWaitListElem>; 55 56 } // namespace ark::taskmanager 57 58 #endif // LIBPANDABASE_TASKMANAGER_TASK_MANAGER_COMMON_H 59