下面是时钟节拍函数的源码
void OSTimeTick (void) { ... OS_TCB *ptcb;
OSTimeTickHook(); /* Call user definable hook */ ...
if (OSRunning == TRUE) { ptcb = OSTCBList; /* Point at first TCB in TCB list */ while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list */ (1) OS_ENTER_CRITICAL(); (2) if (ptcb->OSTCBDly != 0) { /* Delayed or waiting for event with TO */ if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay */ if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended? */ OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make task R-to-R (timed out)*/ OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX; } else { /* Yes, Leave 1 tick to prevent ... */ ptcb->OSTCBDly = 1; /* ... loosing the task when the ... */ } /* ... suspension is removed. */ } } ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */ OS_EXIT_CRITICAL(); (3) } (4) } }
这里(1)(4)是循环体,循环处理每个TCB(除了OSTaskIdle),(2)(3)是进出临界段
我的疑问就是 这里设置临界段是因为要访问全局资源TCB,而while循环的测试条件(1)里面也包含了对TCB优先级的读取,那为什么临界段没有包括while循环判断?既为什么没有包括整个while循环呢?如果是出于对关中断时间的长短的考虑,是不是在功能上出错了呢?
不知道,请大虾指点 |