1 /* 2 * Copyright (c) 2020 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 LITE_TASKMANAGER_H 17 #define LITE_TASKMANAGER_H 18 19 #include <ohos_types.h> 20 #include "thread_adapter.h" 21 #include "service.h" 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 #ifndef MAX_TASK_SIZE 30 #define MAX_TASK_SIZE 0xFFFFFF 31 #endif 32 #define MAX_REF_NUM 15 33 #define MSG_PROC_THRESHOLD (10 * 1000) 34 #define GET_REMAIN_TIME(time) ((0xFFFFFFFF - (time)) + 1) 35 #define GET_INTERVAL(last, now) (((last) > (now)) ? (GET_REMAIN_TIME(last) + (now)) : ((now) - (last))) 36 37 typedef struct TaskPool TaskPool; 38 struct TaskPool { 39 MQueueId queueId; 40 uint16 stackSize; 41 uint8 priority; // task run priority 42 uint8 size; 43 uint8 top; 44 int8 ref; 45 ThreadId tasks[0]; 46 }; 47 TaskPool *SAMGR_CreateFixedTaskPool(const TaskConfig *config, const char *name, uint8 size); 48 int32 SAMGR_StartTaskPool(TaskPool *pool, const char *name); 49 int32 SAMGR_ReleaseTaskPool(TaskPool *pool); 50 TaskPool *SAMGR_ReferenceTaskPool(TaskPool *pool); 51 MQueueId SAMGR_GetCurrentQueueID(void); 52 #ifdef __cplusplus 53 #if __cplusplus 54 } 55 #endif 56 #endif 57 58 #endif // LITE_TASKMANAGER_H 59