|
发表于 2014-10-14 17:33:49
|
显示全部楼层
看了一点里面的程序,如下:
- tByte SCH_Add_Task(void (code * pFunction)(),
- const tWord DELAY,
- const tWord PERIOD)
- {
- tByte Index = 0;
-
- // First find a gap in the array (if there is one)
- while ((SCH_tasks_G[Index].pTask != 0) && (Index < SCH_MAX_TASKS))
- {
- Index++;
- }
-
- // Have we reached the end of the list?
- if (Index == SCH_MAX_TASKS)
- {
- // Task list is full
- //
- // Set the global error variable
- Error_code_G = ERROR_SCH_TOO_MANY_TASKS;
- // Also return an error code
- return SCH_MAX_TASKS;
- }
-
- // If we're here, there is a space in the task array
- SCH_tasks_G[Index].pTask = pFunction;
-
- SCH_tasks_G[Index].Delay = DELAY;
- SCH_tasks_G[Index].Period = PERIOD;
- SCH_tasks_G[Index].RunMe = 0;
- return Index; // return position of task (to allow later deletion)
- }
复制代码
我认为,在创建任务的时候,有必要加入原子保护操作 |
|