| 本帖最后由 solo777 于 2012-1-10 20:08 编辑 
 uint8_t tcbEnqueuePriority (ATOM_TCB **tcb_queue_ptr, ATOM_TCB *tcb_ptr)
 {
 uint8_t status;
 ATOM_TCB *prev_ptr, *next_ptr;
 
 /* Parameter check */
 if ((tcb_queue_ptr == NULL) || (tcb_ptr == NULL))
 {
 /* Return error */
 status = ATOM_ERR_PARAM;
 }
 else
 {
 /* Walk the list and enqueue at the end of the TCBs at this priority */
 prev_ptr = next_ptr = *tcb_queue_ptr;
 do
 {
 /* Insert if:
 *   next_ptr = NULL (we're at the head of an empty queue or at the tail)
 *   the next TCB in the list is lower priority than the one we're enqueuing.
 */
 if ((next_ptr == NULL) || (next_ptr->priority > tcb_ptr->priority))
 {
 /* Make this TCB the new listhead */
 if (next_ptr == *tcb_queue_ptr)//这里也是null呀!
 {
 *tcb_queue_ptr = tcb_ptr;
 
 tcb_ptr->prev_tcb = NULL;                    tcb_ptr->next_tcb = next_ptr;
 
 if (next_ptr)
 next_ptr->prev_tcb = tcb_ptr;
 }
 /* Insert between two TCBs or at the tail */
 else
 {
 tcb_ptr->prev_tcb = prev_ptr;
 tcb_ptr->next_tcb = next_ptr;
 prev_ptr->next_tcb = tcb_ptr;
 if (next_ptr)
 next_ptr->prev_tcb = tcb_ptr;
 }
 
 /* Quit the loop, we've finished inserting */
 break;
 }
 else
 {
 /* Not inserting here, try the next one */
 prev_ptr = next_ptr;
 
 next_ptr = next_ptr->next_tcb;
 
 }
 
 }
 while (prev_ptr != NULL);
 |