hahake 发表于 2010-9-23 11:00:09

ucos 2.84 中的OSTaskStkChk( )

ucos 2.84 中的OSTaskStkChk( )
源码如下:
#if OS_TASK_CREATE_EXT_EN > 0
INT8UOSTaskStkChk (INT8U prio, OS_STK_DATA *p_stk_data)
{
    OS_TCB    *ptcb;
    OS_STK    *pchk;
    INT32U   free;
    INT32U   size;
#if OS_CRITICAL_METHOD == 3                            /* Allocate storage for CPU status register   */
    OS_CPU_SRcpu_sr = 0;
#endif



#if OS_ARG_CHK_EN > 0
    if (prio > OS_LOWEST_PRIO) {                     /* Make sure task priority is valid             */
      if (prio != OS_PRIO_SELF) {
            return (OS_PRIO_INVALID);
      }
    }
    if (p_stk_data == (OS_STK_DATA *)0) {            /* Validate 'p_stk_data'                        */
      return (OS_ERR_PDATA_NULL);
    }
#endif
    p_stk_data->OSFree = 0;                            /* Assume failure, set to 0 size                */
    p_stk_data->OSUsed = 0;
    OS_ENTER_CRITICAL();
    if (prio == OS_PRIO_SELF) {                        /* See if check for SELF                        */
      prio = OSTCBCur->OSTCBPrio;
    }
    ptcb = OSTCBPrioTbl;
    if (ptcb == (OS_TCB *)0) {                         /* Make sure task exist                         */
      OS_EXIT_CRITICAL();
      return (OS_TASK_NOT_EXIST);
    }
    if (ptcb == (OS_TCB *)1) {
      OS_EXIT_CRITICAL();
      return (OS_TASK_NOT_EXIST);
    }
    if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set       */
      OS_EXIT_CRITICAL();
      return (OS_TASK_OPT_ERR);
    }
    free = 0;
    size = ptcb->OSTCBStkSize;
    pchk = ptcb->OSTCBStkBottom;
    OS_EXIT_CRITICAL();
#if OS_STK_GROWTH == 1
    while (*pchk++ == (OS_STK)0) {                  /* Compute the number of zero entries on the stk */
      free++;
    }
#else
    while (*pchk-- == (OS_STK)0) {
      free++;
    }
#endif
    p_stk_data->OSFree = free * sizeof(OS_STK);         /* Compute number of free bytes on the stack */
    p_stk_data->OSUsed = (size - free) * sizeof(OS_STK);/* Compute number of bytes used on the stack */
    return (OS_NO_ERR);
}
#endif

请问这段代码:
    if (ptcb == (OS_TCB *)0) {                         /* Make sure task exist                         */
      OS_EXIT_CRITICAL();
      return (OS_TASK_NOT_EXIST);
    }
    if (ptcb == (OS_TCB *)1) {
      OS_EXIT_CRITICAL();
      return (OS_TASK_NOT_EXIST);
    }
怎么理解,我翻看了2.52版源码 并没有判断 ptcb == (OS_TCB *)1,
上述的代码怎么能够保证任务存在???
页: [1]
查看完整版本: ucos 2.84 中的OSTaskStkChk( )