52#ifdef LOSCFG_KERNEL_CPUP
55#ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
58#ifdef LOSCFG_KERNEL_LITEIPC
61#ifdef LOSCFG_ENABLE_OOM_LOOP_TASK
143#if (LOSCFG_BASE_CORE_TSK_LIMIT <= 0)
144#error "task maxnum cannot be zero"
170 CHAR *name =
"osMain";
173 schedParam.
policy = LOS_SCHED_RR;
174 schedParam.
basePrio = OS_PROCESS_PRIORITY_HIGHEST;
175 schedParam.
priority = OS_TASK_PRIORITY_LOWEST;
177 for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
181#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
185 (VOID)strncpy_s(
g_mainTask[i].taskName, OS_TCB_NAME_LEN, name, OS_TCB_NAME_LEN - 1);
214 if (taskCB->
taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
216 LosTaskCB *resumedTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(&(taskCB->
joinList)));
218 resumedTask->
ops->
wake(resumedTask);
226 if (taskCB->
taskStatus & OS_TASK_STATUS_INIT) {
230 if (taskCB->
taskStatus & OS_TASK_STATUS_EXIT) {
237 return runTask->
ops->
wait(runTask, &taskCB->
joinList, LOS_WAIT_FOREVER);
245 if (taskCB->
taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
248 taskCB->
taskStatus &= ~OS_TASK_FLAG_PTHREAD_JOIN;
273 ret = LOS_ERRNO_TSK_NO_MEMORY;
290 PRINT_ERR(
"OsTaskInit error\n");
308 taskInitParam.
uwStackSize = LOSCFG_BASE_CORE_TSK_IDLE_STACK_SIZE;
309 taskInitParam.
pcName =
"Idle";
310 taskInitParam.
policy = LOS_SCHED_IDLE;
311 taskInitParam.
usTaskPrio = OS_TASK_PRIORITY_LOWEST;
313#ifdef LOSCFG_KERNEL_SMP
320 LosTaskCB *idleTask = OS_TCB_FROM_TID(idleTaskID);
321 idleTask->
taskStatus |= OS_TASK_FLAG_SYSTEM_TASK;
335 if (runTask == NULL) {
336 return LOS_ERRNO_TSK_ID_INVALID;
343#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
346 return LOS_ERRNO_TSK_MP_SYNC_RESOURCE;
356#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
363#ifdef LOSCFG_KERNEL_SMP
374#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
385 ret = LOS_ERRNO_TSK_MP_SYNC_FAILED;
400#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
426 UINT32 syncSignal = LOSCFG_BASE_IPC_SEM_LIMIT;
430#ifdef LOSCFG_KERNEL_VM
432 SCHEDULER_LOCK(intSave);
437 SCHEDULER_UNLOCK(intSave);
442 if ((ret != LOS_OK) && (mapBase != 0) && !
OsProcessIsInit(processCB)) {
443 PRINT_ERR(
"process(%u) unmmap user task(%u) stack failed! mapbase: 0x%x size :0x%x, error: %d\n",
447#ifdef LOSCFG_KERNEL_LITEIPC
453 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
456#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
458 taskCB->
syncSignal = LOSCFG_BASE_IPC_SEM_LIMIT;
462 SCHEDULER_LOCK(intSave);
463#ifdef LOSCFG_KERNEL_VM
467 SCHEDULER_UNLOCK(intSave);
476 SCHEDULER_LOCK(intSave);
480 SCHEDULER_UNLOCK(intSave);
484 SCHEDULER_LOCK(intSave);
486 SCHEDULER_UNLOCK(intSave);
495 LOS_ASSERT(!OS_TID_CHECK_INVALID(taskID));
505 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
508 if (!(taskCB->
taskStatus & OS_TASK_FLAG_PTHREAD_JOIN)) {
518 UINT32 poolSize = OS_SYS_MEM_SIZE;
521 if (taskID == NULL) {
522 return LOS_ERRNO_TSK_ID_INVALID;
525 if (initParam == NULL) {
526 return LOS_ERRNO_TSK_PTR_NULL;
531 if (initParam->
pcName == NULL) {
532 return LOS_ERRNO_TSK_NAME_EMPTY;
537 return LOS_ERRNO_TSK_ENTRY_NULL;
540 if (initParam->
usTaskPrio > OS_TASK_PRIORITY_LOWEST) {
541 return LOS_ERRNO_TSK_PRIOR_ERROR;
545 return LOS_ERRNO_TSK_STKSZ_TOO_LARGE;
549 initParam->
uwStackSize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
553 if (initParam->
uwStackSize < LOS_TASK_MIN_STACK_SIZE) {
554 return LOS_ERRNO_TSK_STKSZ_TOO_SMALL;
577 taskCB->
signal = SIGNAL_NONE;
579#ifdef LOSCFG_KERNEL_SMP
580 taskCB->
currCpu = OS_TASK_INVALID_CPUID;
585 if (initParam->
uwResved & LOS_TASK_ATTR_JOINABLE) {
586 taskCB->
taskStatus |= OS_TASK_FLAG_PTHREAD_JOIN;
591 SET_SORTLIST_VALUE(&taskCB->
sortList, OS_SORT_LINK_INVALID_TIME);
595 const VOID *stackPtr,
const VOID *topStack)
600 UINT16 policy = (initParam->
policy == LOS_SCHED_NORMAL) ? LOS_SCHED_RR : initParam->
policy;
605 schedParam.
policy = policy;
607#ifdef LOSCFG_KERNEL_VM
609 if (taskCB->
taskStatus & OS_TASK_FLAG_USER_MODE) {
623 if (initParam->
pcName != NULL) {
630 if (snprintf_s(taskCB->
taskName, OS_TCB_NAME_LEN, OS_TCB_NAME_LEN - 1,
"thread%u", numCount) < 0) {
640 SCHEDULER_LOCK(intSave);
642 SCHEDULER_UNLOCK(intSave);
643 PRINT_ERR(
"No idle TCB in the system!\n");
649 SCHEDULER_UNLOCK(intSave);
666 VOID *topStack = NULL;
670 if (errRet != LOS_OK) {
675 if (taskCB == NULL) {
676 errRet = LOS_ERRNO_TSK_TCB_UNAVAILABLE;
681 if (errRet != LOS_OK) {
682 goto LOS_ERREND_REWIND_TCB;
686 if (topStack == NULL) {
687 errRet = LOS_ERRNO_TSK_NO_MEMORY;
688 goto LOS_ERREND_REWIND_SYNC;
692 errRet =
OsTaskCBInit(taskCB, initParam, stackPtr, topStack);
693 if (errRet != LOS_OK) {
694 goto LOS_ERREND_TCB_INIT;
701 OsHookCall(LOS_HOOK_TYPE_TASK_CREATE, taskCB);
706LOS_ERREND_REWIND_SYNC:
707#ifdef LOSCFG_KERNEL_SMP_TASK_SYNC
710LOS_ERREND_REWIND_TCB:
711 SCHEDULER_LOCK(intSave);
713 SCHEDULER_UNLOCK(intSave);
723 if (initParam == NULL) {
724 return LOS_ERRNO_TSK_PTR_NULL;
728 return LOS_ERRNO_TSK_YIELD_IN_INT;
742 LosTaskCB *taskCB = OS_TCB_FROM_TID(*taskID);
744 SCHEDULER_LOCK(intSave);
746 SCHEDULER_UNLOCK(intSave);
751 if (OS_SCHEDULER_ACTIVE) {
762 BOOL needSched = FALSE;
764 if (OS_TID_CHECK_INVALID(taskID)) {
765 return LOS_ERRNO_TSK_ID_INVALID;
768 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
769 SCHEDULER_LOCK(intSave);
772 taskCB->
signal &= ~SIGNAL_SUSPEND;
774 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
775 errRet = LOS_ERRNO_TSK_NOT_CREATED;
777 }
else if (!(taskCB->
taskStatus & OS_TASK_STATUS_SUSPENDED)) {
778 errRet = LOS_ERRNO_TSK_NOT_SUSPENDED;
782 errRet = taskCB->
ops->
resume(taskCB, &needSched);
783 SCHEDULER_UNLOCK(intSave);
786 if (OS_SCHEDULER_ACTIVE && needSched) {
793 SCHEDULER_UNLOCK(intSave);
811#ifdef LOSCFG_KERNEL_SMP
814 taskCB->
signal = SIGNAL_SUSPEND;
822 *ret = LOS_ERRNO_TSK_SUSPEND_LOCKED;
828 taskCB->
signal = SIGNAL_SUSPEND;
839 if (tempStatus & OS_TASK_STATUS_UNUSED) {
840 return LOS_ERRNO_TSK_NOT_CREATED;
843 if (tempStatus & OS_TASK_STATUS_SUSPENDED) {
844 return LOS_ERRNO_TSK_ALREADY_SUSPENDED;
847 if ((tempStatus & OS_TASK_STATUS_RUNNING) &&
860 if (OS_TID_CHECK_INVALID(taskID)) {
861 return LOS_ERRNO_TSK_ID_INVALID;
864 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
865 if (taskCB->
taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
866 return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
869 SCHEDULER_LOCK(intSave);
871 SCHEDULER_UNLOCK(intSave);
880 OS_MEM_CLEAR(taskCB->
taskID);
889 mux = LOS_DL_LIST_ENTRY(LOS_DL_LIST_FIRST(&taskCB->
lockList),
LosMux, holdList);
893 PRINT_ERR(
"mux ulock failed! : %u\n", ret);
897#ifdef LOSCFG_KERNEL_VM
898 if (taskCB->
taskStatus & OS_TASK_FLAG_USER_MODE) {
916 OsHookCall(LOS_HOOK_TYPE_TASK_DELETE, runTask);
918 SCHEDULER_LOCK(intSave);
920 SCHEDULER_UNLOCK(intSave);
925 SCHEDULER_LOCK(intSave);
930 }
else if (runTask->
taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) {
933 SCHEDULER_UNLOCK(intSave);
937 SCHEDULER_LOCK(intSave);
943 SCHEDULER_UNLOCK(intSave);
954 if (taskStatus & OS_TASK_STATUS_PENDING) {
965 OsHookCall(LOS_HOOK_TYPE_TASK_DELETE, taskCB);
973 if (OS_TID_CHECK_INVALID(taskID)) {
974 return LOS_ERRNO_TSK_ID_INVALID;
978 return LOS_ERRNO_TSK_YIELD_IN_INT;
981 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
984 return LOS_ERRNO_TSK_DELETE_LOCKED;
990 SCHEDULER_LOCK(intSave);
991 if (taskCB->
taskStatus & (OS_TASK_STATUS_UNUSED | OS_TASK_FLAG_SYSTEM_TASK | OS_TASK_FLAG_NO_DELETE)) {
992 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
993 ret = LOS_ERRNO_TSK_NOT_CREATED;
995 ret = LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
1000#ifdef LOSCFG_KERNEL_SMP
1001 if (taskCB->
taskStatus & OS_TASK_STATUS_RUNNING) {
1002 taskCB->
signal = SIGNAL_KILL;
1013 SCHEDULER_UNLOCK(intSave);
1014 if (ret == LOS_OK) {
1024 if (OS_INT_ACTIVE) {
1025 PRINT_ERR(
"In interrupt not allow delay task!\n");
1026 return LOS_ERRNO_TSK_DELAY_IN_INT;
1030 if (runTask->
taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
1032 return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
1036 return LOS_ERRNO_TSK_DELAY_IN_LOCK;
1038 OsHookCall(LOS_HOOK_TYPE_TASK_DELAY, tick);
1043 SCHEDULER_LOCK(intSave);
1044 UINT32 ret = runTask->
ops->
delay(runTask, OS_SCHED_TICK_TO_CYCLE(tick));
1045 OsHookCall(LOS_HOOK_TYPE_MOVEDTASKTODELAYEDLIST, runTask);
1046 SCHEDULER_UNLOCK(intSave);
1055 if (OS_TID_CHECK_INVALID(taskID)) {
1056 return (
UINT16)OS_INVALID;
1059 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1060 SCHEDULER_LOCK(intSave);
1061 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1062 SCHEDULER_UNLOCK(intSave);
1063 return (
UINT16)OS_INVALID;
1067 SCHEDULER_UNLOCK(intSave);
1076 if (taskPrio > OS_TASK_PRIORITY_LOWEST) {
1077 return LOS_ERRNO_TSK_PRIOR_ERROR;
1080 if (OS_TID_CHECK_INVALID(taskID)) {
1081 return LOS_ERRNO_TSK_ID_INVALID;
1084 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1085 if (taskCB->
taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
1086 return LOS_ERRNO_TSK_OPERATE_SYSTEM_TASK;
1089 SCHEDULER_LOCK(intSave);
1090 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1091 SCHEDULER_UNLOCK(intSave);
1092 return LOS_ERRNO_TSK_NOT_CREATED;
1100 SCHEDULER_UNLOCK(intSave);
1103 if (needSched && OS_SCHEDULER_ACTIVE) {
1119 if (OS_INT_ACTIVE) {
1120 return LOS_ERRNO_TSK_YIELD_IN_INT;
1124 return LOS_ERRNO_TSK_YIELD_IN_LOCK;
1128 if (OS_TID_CHECK_INVALID(runTask->
taskID)) {
1129 return LOS_ERRNO_TSK_ID_INVALID;
1132 SCHEDULER_LOCK(intSave);
1135 SCHEDULER_UNLOCK(intSave);
1166 if (taskInfo == NULL) {
1167 return LOS_ERRNO_TSK_PTR_NULL;
1170 if (OS_TID_CHECK_INVALID(taskID)) {
1171 return LOS_ERRNO_TSK_ID_INVALID;
1174 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1175 SCHEDULER_LOCK(intSave);
1176 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1177 SCHEDULER_UNLOCK(intSave);
1178 return LOS_ERRNO_TSK_NOT_CREATED;
1181 if (!(taskCB->
taskStatus & OS_TASK_STATUS_RUNNING) || OS_INT_ACTIVE) {
1197 if (strncpy_s(taskInfo->
acName, LOS_TASK_NAMELEN, taskCB->
taskName, LOS_TASK_NAMELEN - 1) != EOK) {
1198 PRINT_ERR(
"Task name copy failed!\n");
1200 taskInfo->
acName[LOS_TASK_NAMELEN - 1] =
'\0';
1203 OS_TASK_STACK_ADDR_ALIGN);
1208 SCHEDULER_UNLOCK(intSave);
1214#ifdef LOSCFG_KERNEL_SMP
1215 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1218 *oldCpuAffiMask = CPUID_TO_AFFI_MASK(taskCB->
currCpu);
1219 if (!((*oldCpuAffiMask) & newCpuAffiMask)) {
1220 taskCB->
signal = SIGNAL_AFFI;
1225 (VOID)newCpuAffiMask;
1226 (VOID)oldCpuAffiMask;
1233 BOOL needSched = FALSE;
1237 if (OS_TID_CHECK_INVALID(taskID)) {
1238 return LOS_ERRNO_TSK_ID_INVALID;
1241 if (!(cpuAffiMask & LOSCFG_KERNEL_CPU_MASK)) {
1242 return LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR;
1245 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1246 SCHEDULER_LOCK(intSave);
1247 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1248 SCHEDULER_UNLOCK(intSave);
1249 return LOS_ERRNO_TSK_NOT_CREATED;
1253 SCHEDULER_UNLOCK(intSave);
1255 if (needSched && OS_SCHEDULER_ACTIVE) {
1265#ifdef LOSCFG_KERNEL_SMP
1266#define INVALID_CPU_AFFI_MASK 0
1270 if (OS_TID_CHECK_INVALID(taskID)) {
1271 return INVALID_CPU_AFFI_MASK;
1274 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1275 SCHEDULER_LOCK(intSave);
1276 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1277 SCHEDULER_UNLOCK(intSave);
1278 return INVALID_CPU_AFFI_MASK;
1282 SCHEDULER_UNLOCK(intSave);
1308 if (runTask->
signal == SIGNAL_NONE) {
1312 if (runTask->
signal & SIGNAL_KILL) {
1317 runTask->
signal = SIGNAL_NONE;
1319 if (ret != LOS_OK) {
1320 PRINT_ERR(
"Task proc signal delete task(%u) failed err:0x%x\n", runTask->
taskID, ret);
1322 }
else if (runTask->
signal & SIGNAL_SUSPEND) {
1323 runTask->
signal &= ~SIGNAL_SUSPEND;
1327#ifdef LOSCFG_KERNEL_SMP
1328 }
else if (runTask->
signal & SIGNAL_AFFI) {
1329 runTask->
signal &= ~SIGNAL_AFFI;
1341 const CHAR *namePtr = NULL;
1342 CHAR nameBuff[OS_TCB_NAME_LEN] = { 0 };
1344 if ((taskCB == NULL) || (name == NULL)) {
1358 SCHEDULER_LOCK(intSave);
1360 err = strncpy_s(taskCB->
taskName, OS_TCB_NAME_LEN, (VOID *)namePtr, OS_TCB_NAME_LEN - 1);
1370 if (err != LOS_OK) {
1376 SCHEDULER_UNLOCK(intSave);
1387 if (taskCB == NULL) {
1391 if (processID == OS_INVALID_VALUE) {
1395 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1410 if (param == NULL) {
1411 return OS_INVALID_VALUE;
1416 return OS_INVALID_VALUE;
1420 return OS_INVALID_VALUE;
1424 return OS_INVALID_VALUE;
1428 return OS_INVALID_VALUE;
1441 if (ret != LOS_OK) {
1445 initParam->
uwStackSize = OS_USER_TASK_SYSCALL_STACK_SIZE;
1446 initParam->
usTaskPrio = OS_TASK_PRIORITY_LOWEST;
1447 initParam->
policy = LOS_SCHED_RR;
1448 if (processID == OS_INVALID_VALUE) {
1449 SCHEDULER_LOCK(intSave);
1453 SCHEDULER_UNLOCK(intSave);
1460 if (ret != LOS_OK) {
1461 return OS_INVALID_VALUE;
1473 if (OS_TID_CHECK_INVALID(taskID)) {
1477 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1478 SCHEDULER_LOCK(intSave);
1479 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1480 policy = -LOS_EINVAL;
1488 SCHEDULER_UNLOCK(intSave);
1498 if (OS_TID_CHECK_INVALID(taskID)) {
1502 if (priority > OS_TASK_PRIORITY_LOWEST) {
1506 if ((policy != LOS_SCHED_FIFO) && (policy != LOS_SCHED_RR)) {
1510 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1511 if (taskCB->
taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
1515 SCHEDULER_LOCK(intSave);
1516 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1517 SCHEDULER_UNLOCK(intSave);
1525 SCHEDULER_UNLOCK(intSave);
1528 if (needSched && OS_SCHEDULER_ACTIVE) {
1537 if (OS_TID_CHECK_INVALID(taskID)) {
1541 if (OS_INT_ACTIVE) {
1549 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1550 if (taskCB->
taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
1568 if (errRet != LOS_OK) {
1572 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1573 SCHEDULER_LOCK(intSave);
1574 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1575 SCHEDULER_UNLOCK(intSave);
1580 SCHEDULER_UNLOCK(intSave);
1585 SCHEDULER_UNLOCK(intSave);
1587 if (errRet == LOS_OK) {
1590 if (retval != NULL) {
1607 if (OS_TID_CHECK_INVALID(taskID)) {
1611 if (OS_INT_ACTIVE) {
1615 LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
1616 SCHEDULER_LOCK(intSave);
1617 if (taskCB->
taskStatus & OS_TASK_STATUS_UNUSED) {
1618 SCHEDULER_UNLOCK(intSave);
1623 SCHEDULER_UNLOCK(intSave);
1627 if (taskCB->
taskStatus & OS_TASK_STATUS_EXIT) {
1628 SCHEDULER_UNLOCK(intSave);
1633 SCHEDULER_UNLOCK(intSave);
1658 LOS_WAITMODE_OR | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
1659 if (ret & (OS_RESOURCE_EVENT_FREE | OS_RESOURCE_EVENT_OOM)) {
1664#ifdef LOSCFG_ENABLE_OOM_LOOP_TASK
1665 if (ret & OS_RESOURCE_EVENT_OOM) {
1679 if (ret != LOS_OK) {
1685 taskInitParam.
uwStackSize = OS_TASK_RESOURCE_STATIC_SIZE;
1686 taskInitParam.
pcName =
"ResourcesTask";
1687 taskInitParam.
usTaskPrio = OS_TASK_RESOURCE_FREE_PRIORITY;
1689 if (ret == LOS_OK) {
1690 OS_TCB_FROM_TID(taskID)->taskStatus |= OS_TASK_FLAG_NO_DELETE;
macro EXC_SP_SET stackSize
LITE_OS_SEC_TEXT UINT32 LOS_EventRead(PEVENT_CB_S eventCB, UINT32 eventMask, UINT32 mode, UINT32 timeout)
读取指定事件类型,超时时间为相对时间:单位为Tick
LITE_OS_SEC_TEXT UINT32 LOS_EventWrite(PEVENT_CB_S eventCB, UINT32 events)
写指定的事件类型
LITE_OS_SEC_TEXT_INIT UINT32 LOS_EventInit(PEVENT_CB_S eventCB)
初始化一个事件控制块
VOID OsBackTrace(VOID)
Kernel backtrace function.
STATIC INLINE UINT32 LOS_IntUnLock(VOID)
Enable all interrupts. | 打开当前处理器所有中断响应
STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
Restore interrupts. | 恢复到使用LOS_IntLock关闭所有中断之前的状态
STATIC INLINE UINT32 LOS_IntLock(VOID)
Disable all interrupts. | 关闭当前处理器所有中断响应
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListTailInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the tail of a doubly linked list.
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a new node to a doubly linked list.
LITE_OS_SEC_ALW_INLINE STATIC INLINE BOOL LOS_ListEmpty(LOS_DL_LIST *list)
Identify whether a specified doubly linked list is empty. | 判断链表是否为空
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
VOID * LOS_MemAllocAlign(VOID *pool, UINT32 size, UINT32 boundary)
从指定内存池中申请size长度的内存且地址按boundary字节对齐的内存
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
UINT8 * m_aucSysMem0
异常交互动态内存池地址的起始地址,当不支持异常交互特性时,m_aucSysMem0等于m_aucSysMem1。
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle)
对外接口 创建信号量
LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
对外接口 申请指定的信号量,并设置超时时间
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle)
对外接口 删除指定的信号量,参数就是 semID
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskCpuAffiSet(UINT32 taskID, UINT16 cpuAffiMask)
Set the affinity mask of the task scheduling cpu.
UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, UINT32 *peakUsed)
Get stack waterline.
LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskUnlock(VOID)
Unlock the task scheduling.
LITE_OS_SEC_BSS UINT32 g_taskMaxNum
任务最大数量 默认128个
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskDelete(UINT32 taskID)
Delete a task.
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CurTaskPriSet(UINT16 taskPrio)
设置当前任务的优先级
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskResume(UINT32 taskID)
恢复挂起的任务,使该任务进入ready状态
UINT32 LOS_TaskDetach(UINT32 taskID)
Change the joinable attribute of the task to detach.
LITE_OS_SEC_TEXT UINT32 LOS_CurTaskIDGet(VOID)
Obtain current running task ID.
LITE_OS_SEC_TEXT UINT32 LOS_GetSystemTaskMaximum(VOID)
Gets the maximum number of threads supported by the system.
LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskPriGet(UINT32 taskID)
获取任务的优先级
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskYield(VOID)
Change the scheduling sequence of tasks with the same priority.
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskPriSet(UINT32 taskID, UINT16 taskPrio)
设置指定任务的优先级
LITE_OS_SEC_TEXT INT32 LOS_GetTaskScheduler(INT32 taskID)
获取任务的调度方式
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreateOnly(UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
LOS_TaskCreateOnly 创建任务,并使该任务进入suspend状态,不对该任务进行调度。如果需要调度,可以调用LOS_TaskResume使该任务进入ready状态
LITE_OS_SEC_TEXT INT32 LOS_SetTaskScheduler(INT32 taskID, UINT16 policy, UINT16 priority)
Set the scheduling policy and priority for the task.
struct tagTskInitParam TSK_INIT_PARAM_S
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskSuspend(UINT32 taskID)
外部接口,对OsTaskSuspend的封装
LITE_OS_SEC_TEXT_MINOR VOID LOS_TaskLock(VOID)
Lock the task scheduling.
LITE_OS_SEC_BSS LosTaskCB * g_taskCBArray
外部变量 任务池 默认128个
LITE_OS_SEC_TEXT_INIT UINT32 LOS_TaskCreate(UINT32 *taskID, TSK_INIT_PARAM_S *initParam)
创建任务,并使该任务进入ready状态,如果就绪队列中没有更高优先级的任务,则运行该任务
VOID LOS_Schedule(VOID)
Trigger active task scheduling.
LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick)
任务延时等待,释放CPU,等待时间到期后该任务会重新进入ready状态
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_TaskInfoGet(UINT32 taskID, TSK_INFO_S *taskInfo)
Obtain a task information structure.
VOID *(* TSK_ENTRY_FUNC)(UINTPTR param1, UINTPTR param2, UINTPTR param3, UINTPTR param4)
Define the type of a task entrance function.
UINT32 LOS_TaskJoin(UINT32 taskID, UINTPTR *retval)
Wait for the specified task to finish and reclaim its resources.
LITE_OS_SEC_TEXT_MINOR UINT16 LOS_TaskCpuAffiGet(UINT32 taskID)
查询任务被绑在哪个CPU上
LITE_OS_SEC_TEXT VOID LiteIpcRemoveServiceHandle(UINT32 taskID)
删除指定的Service
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS)))
VOID OsEventWriteUnsafe(PEVENT_CB_S eventCB, UINT32 events, BOOL once, UINT8 *exitFlag)
以不安全的方式写事件
VOID OsFutexNodeDeleteFromFutexHash(FutexNode *node, BOOL isDeleteHead, FutexNode **headNode, BOOL *queueFlags)
从哈希桶上删除快锁
STATIC INLINE UINT32 ArchSPGet(VOID)
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
VOID * OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag)
内核态任务运行栈初始化
VOID OsUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
用户态运行栈初始化,此时上下文还在内核区
VOID LOS_MpSchedule(UINT32 target)
LITE_OS_SEC_TEXT BOOL LOS_MuxIsValid(const LosMux *mutex)
互斥锁是否有效
VOID OsMuxBitmapRestore(const LosMux *mutex, const LOS_DL_LIST *list, const LosTaskCB *runTask)
恢复互斥锁位图
UINT32 OsMuxUnlockUnsafe(LosTaskCB *taskCB, LosMux *mutex, BOOL *needSched)
LITE_OS_SEC_TEXT_MINOR BOOL OomCheckProcess(VOID)
LITE_OS_SEC_TEXT UINT32 OsGetIdleProcessID(VOID)
获取内核态空闲进程
VOID OsDeleteTaskFromProcess(LosTaskCB *taskCB)
LITE_OS_SEC_TEXT UINT32 OsGetKernelInitProcessID(VOID)
获取内核态根进程
VOID OsProcessNaturalExit(LosProcessCB *processCB, UINT32 status)
UINT32 OsProcessAddNewTask(UINT32 pid, LosTaskCB *taskCB, SchedParam *param)
LITE_OS_SEC_TEXT VOID OsProcessThreadGroupDestroy(VOID)
LITE_OS_SEC_TEXT VOID OsProcessCBRecycleToFree(VOID)
UINT32 OsSetProcessName(LosProcessCB *processCB, const CHAR *name)
LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
STATIC INLINE LosVmSpace * OsProcessVmSpaceGet(const LosProcessCB *processCB)
STATIC INLINE UINT32 OsProcessThreadGroupIDGet(const LosTaskCB *taskCB)
STATIC INLINE UINT32 OsProcessThreadNumberGet(const LosTaskCB *taskCB)
STATIC INLINE BOOL OsProcessIsInit(const LosProcessCB *processCB)
STATIC INLINE BOOL OsProcessIsUserMode(const LosProcessCB *processCB)
STATIC INLINE LosProcessCB * OsCurrProcessGet(VOID)
STATIC INLINE BOOL OsSchedUnlockResch(VOID)
struct TagTaskCB LosTaskCB
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
VOID OsSchedRunqueueIdleInit(UINT32 idleTaskID)
STATIC INLINE BOOL OsPreemptableInSched(VOID)
STATIC INLINE BOOL OsPreemptable(VOID)
STATIC INLINE SchedRunqueue * OsSchedRunqueue(VOID)
STATIC INLINE UINT32 OsSchedRunqueueIdleGet(VOID)
UINT32 OsSchedParamInit(LosTaskCB *taskCB, UINT16 policy, const SchedParam *parentParam, const TSK_INIT_PARAM_S *param)
STATIC INLINE VOID OsSchedLock(VOID)
VOID OsSchedResched(VOID)
UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched)
以不安全的方式释放指定的信号量,所谓不安全指的是不用自旋锁
VOID OsClearSigInfoTmpList(sig_cb *sigcb)
BOOL LOS_SpinHeld(const SPIN_LOCK_S *lock)
VOID LOS_SpinLock(SPIN_LOCK_S *lock)
VOID LOS_SpinUnlock(SPIN_LOCK_S *lock)
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsCreateUserTaskParamCheck(UINT32 processID, TSK_INIT_PARAM_S *param)
创建任务之前,检查用户态任务栈的参数,是否地址在用户空间
LITE_OS_SEC_BSS LOS_DL_LIST g_losFreeTask
STATIC VOID OsConsoleIDSetHook(UINT32 param1, UINT32 param2) __attribute__((weakref("OsSetConsoleID")))
STATIC INLINE VOID OsInsertTCBToFreeList(LosTaskCB *taskCB)
STATIC INLINE VOID OsTaskStatusUnusedSet(LosTaskCB *taskCB)
设置任务为不使用状态
STATIC INLINE VOID OsTaskSyncWake(const LosTaskCB *taskCB)
同步唤醒
LITE_OS_SEC_TEXT VOID OsTaskCBRecycleToFree()
LITE_OS_SEC_TEXT UINT32 OsResourceFreeTaskCreate(VOID)
创建一个回收资源的任务
LITE_OS_SEC_TEXT_INIT STATIC BOOL OsTaskSuspendCheckOnRun(LosTaskCB *taskCB, UINT32 *ret)
STATIC VOID OsTaskReleaseHoldLock(LosTaskCB *taskCB)
STATIC VOID OsResourceRecoveryTask(VOID)
资源回收任务
STATIC VOID OsTaskKernelResourcesToFree(UINT32 syncSignal, UINTPTR topOfStack)
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCreateParamCheck(const UINT32 *taskID, TSK_INIT_PARAM_S *initParam, VOID **pool)
任务创建参数检查
LITE_OS_SEC_TEXT_INIT UINT32 OsIdleTaskCreate(VOID)
创建一个空闲任务
LosTaskCB * OsGetMainTask()
LITE_OS_SEC_BSS LOS_DL_LIST g_taskRecycleList
STATIC INLINE VOID OsTaskSyncDestroy(UINT32 syncSignal)
销毁指定任务同步信号量
LITE_OS_SEC_TEXT_INIT UINT32 OsTaskInit(VOID)
INT32 OsUserProcessOperatePermissionsCheck(const LosTaskCB *taskCB, UINT32 processID)
LITE_OS_SEC_TEXT STATIC UINT32 OsTaskSuspend(LosTaskCB *taskCB)
任务暂停,参数可以不是当前任务,也就是说 A任务可以让B任务处于阻塞状态,挂起指定的任务,然后切换任务
LITE_OS_SEC_TEXT BOOL OsTaskCpuAffiSetUnsafe(UINT32 taskID, UINT16 newCpuAffiMask, UINT16 *oldCpuAffiMask)
CPU亲和性(affinity)将任务绑在指定CPU上,用于多核CPU情况,(该函数仅在SMP模式下支持)
LITE_OS_SEC_BSS STATIC LosTaskCB g_mainTask[LOSCFG_KERNEL_CORE_NUM]
UINT32 OsGetIdleTaskId(VOID)
获取IdletaskId,每个CPU核都对Task进行了内部管理,做到真正的并行处理
STATIC INLINE UINT32 OsTaskSyncCreate(LosTaskCB *taskCB)
创建指定任务同步信号量
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_taskSpin)
LITE_OS_SEC_TEXT UINT32 OsTaskJoinPendUnsafe(LosTaskCB *taskCB)
挂起任务,任务进入等待链表,Join代表是支持通过一个任务去唤醒其他的任务
LITE_OS_SEC_TEXT INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName)
LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID)
STATIC UINT32 OsTaskJoinCheck(UINT32 taskID)
LOS_MODULE_INIT(OsResourceFreeTaskCreate, LOS_INIT_LEVEL_KMOD_TASK)
STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_INIT_PARAM_S *initParam, const VOID *stackPtr, const VOID *topStack)
任务初始化
LITE_OS_SEC_TEXT_MINOR VOID OsTaskProcSignal(VOID)
LITE_OS_SEC_TEXT WEAK VOID OsIdleTask(VOID)
空闲任务,每个CPU都有自己的空闲任务
LITE_OS_SEC_TEXT VOID OsWriteResourceEventUnsafe(UINT32 events)
LITE_OS_SEC_TEXT VOID OsWriteResourceEvent(UINT32 events)
LITE_OS_SEC_BSS UINT32 g_taskScheduled
STATIC INLINE UINT32 OsTaskSyncWait(const LosTaskCB *taskCB)
OsTaskSyncWait 任务同步等待,通过信号量保持同步
LITE_OS_SEC_TEXT LosTaskCB * OsGetFreeTaskCB(VOID)
获取一个空闲TCB
STATIC VOID TaskCBBaseInit(LosTaskCB *taskCB, const VOID *stackPtr, const VOID *topStack, const TSK_INIT_PARAM_S *initParam)
任务基本信息的初始化
VOID OsTaskInsertToRecycleList(LosTaskCB *taskCB)
LITE_OS_SEC_TEXT VOID OsInactiveTaskDelete(LosTaskCB *taskCB)
LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskStackAlloc(VOID **topStack, UINT32 stackSize, VOID *pool)
任务栈(内核态)内存分配,由内核态进程空间提供,即 KProcess 的进程空间
INT32 OsUserTaskOperatePermissionsCheck(const LosTaskCB *taskCB)
LITE_OS_SEC_TEXT_INIT VOID OsTaskJoinPostUnsafe(LosTaskCB *taskCB)
OsTaskJoinPostUnsafe 查找task 通过 OS_TCB_FROM_PENDLIST 来完成,相当于由LOS_DL_LIST找到LosTaskCB,...
STATIC VOID OsTaskResourcesToFree(LosTaskCB *taskCB)
LITE_OS_SEC_TEXT UINT32 OsTaskSetDetachUnsafe(LosTaskCB *taskCB)
任务设置分离模式 Deatch和JOIN是一对有你没我的状态
LITE_OS_SEC_TEXT VOID OsRunningTaskToExit(LosTaskCB *runTask, UINT32 status)
LITE_OS_SEC_BSS EVENT_CB_S g_resourceEvent
LITE_OS_SEC_TEXT_INIT UINT32 OsCreateUserTask(UINT32 processID, TSK_INIT_PARAM_S *initParam)
创建一个用户态任务
STATIC INLINE VOID OsTaskWaitSetPendMask(UINT16 mask, UINTPTR lockID, UINT32 timeout)
设置事件阻塞掩码,即设置任务的等待事件.
STATIC INLINE VOID OsTaskWakeClearPendMask(LosTaskCB *resumeTask)
清除事件阻塞掩码,即任务不再等待任何事件.
STATIC INLINE BOOL LOS_IsUserAddressRange(VADDR_T vaddr, size_t len)
虚拟地址[vaddr,vaddr + len]是否在用户空间
STATIC INLINE BOOL LOS_IsUserAddress(VADDR_T vaddr)
虚拟地址是否在用户空间
STATUS_T OsUnMMap(LosVmSpace *space, VADDR_T addr, size_t size)
INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
VOID(* exit)(LosTaskCB *taskCB)
任务退出
UINT32(* resume)(LosTaskCB *taskCB, BOOL *needSched)
恢复任务
VOID(* enqueue)(SchedRunqueue *rq, LosTaskCB *taskCB)
入队列
UINT32(* delay)(LosTaskCB *taskCB, UINT64 waitTime)
延时执行
UINT32(* wait)(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 timeout)
任务等待
VOID(* wake)(LosTaskCB *taskCB)
任务唤醒
VOID(* yield)(LosTaskCB *taskCB)
让出控制权
UINT32(* suspend)(LosTaskCB *taskCB)
挂起任务
BOOL(* schedParamModify)(LosTaskCB *taskCB, const SchedParam *param)
修改调度参数
UINT32(* schedParamGet)(const LosTaskCB *taskCB, SchedParam *param)
获取调度参数
FutexNode futex
指明任务在等待哪把快锁,一次只等一锁,锁和任务的关系是(1:N)关系
sig_cb sig
信号控制块,用于异步通信,类似于 linux singal模块
UINTPTR userMapBase
用户空间的栈顶位置,内存来自用户空间,和topOfStack有本质的区别.
CHAR taskName[OS_TCB_NAME_LEN]
UINTPTR userArea
用户空间的堆区开始位置
UINT32 userMapSize
用户空间的栈大小,栈底 = userMapBase + userMapSize
UINTPTR userArea
用户空间的堆区开始位置
UINTPTR userMapBase
用户空间的栈顶位置.
UINTPTR userSP
用户空间当前栈指针位置
CHAR acName[LOS_TASK_NAMELEN]
TSK_ENTRY_FUNC pfnTaskEntry
UserTaskParam userParam
任务用户态运行时任何参数