Void OS_PendListInsertPrio (OS_PEND_LIST * p_pend_list,
OS_PEND_DATA * p_pend_data)
{
OS_PRIO prio;
OS_TCB * p_tcb;
OS_TCB * p_tcb_next;
OS_PEND_DATA * p_pend_data_prev;
OS_PEND_DATA * p_pend_data_next;
P_tcb=p_pend_data - & gt; TCBPtr;/* Obtain the priority of the task to insert */
Prio=p_tcb - & gt; Prio;/* for current incoming waiting for the task priority */
If (p_pend_list - & gt; NbrEntries==0) (OS_OBJ_QTY) {/* if a task is the first task waiting for the target object *//* CASE 0: Insert the when there are no entries */
P_pend_list - & gt; NbrEntries=(OS_OBJ_QTY) 1;/* the task of waiting list number 1 *//* This is the first entry */
P_pend_data - & gt; NextPtr=0 (OS_PEND_DATA *);/* introduced into the structure of the pointer to the next is 0 *//* No other OS_PEND_DATAs */in the list are
P_pend_data - & gt; PrevPtr=0 (OS_PEND_DATA *);/* this is introduced into the structure of the pointer to the previous 0 */
P_pend_list - & gt; HeadPtr=p_pend_data;/* who pointed to the table first p_pend_list structure & gt; HeadPtr *//* */
P_pend_list - & gt; TailPtr=p_pend_data;/* who points to the structure table tail p_pend_list - & gt; TailPtr */
} else {/* if the task is not the first to wait for the target object task */
P_pend_list - & gt; NbrEntries++;/* the task of waiting list number 1 *//* CASE 1: One more OS_PEND_DATA */in the list are
P_pend_data_next=p_pend_list - & gt; HeadPtr;/* the watch first address is assigned to the middle of a pointer variable p_pend_data_next */
While (p_pend_data_next!=0) (OS_PEND_DATA *) {/* this time table first address the nature is not 0, but the first object in the list of addresses, namely p_pend_data_next *//* Find the position where to insert */
P_tcb_next=p_pend_data_next - & gt; TCBPtr;/* this is the purpose of this into the task priority and starting from the header of each node of the priority of the task, */
If (prio & lt; P_tcb_next - & gt; Prio) {/* if the priority of this task than the task of the meter high priority, directly out of the while, first inserts into the table, as long as the while no circulation, do only once, so while popup will enter the table after the first insert, */
break;/* if the priority of this task than the task of the meter high priority, directly out of the while, */
//if whil the second loop into this condition, then jump out of the loop after entering the middle insert
/* Found! . Insert BEFORE current */
} else {
P_pend_data_next=p_pend_data_next - & gt; NextPtr; Second insert/* * if the priority of this task has lower precedence than the task of the meter, then the header of the next pointer assignment of 0 to p_pend_data_next, (also as a condition of cyclic query lowest priority), exit the while loop, into the tail into the if operation *//* Not Found, follow the list */
}//第三次插入操作,因为任务比表首的任务优先级低所以进入了这一步操作pend_data_next-> NextPtr points to is the second node in the linked list, not to 0, cannot exit circulation, continue to cycle through the while,
//the purpose of this line will be a lower priority node to the end of the list of mobile////for members of the second node priority compared with the priority of this task into the
//variable p_pend_data_next assigned to nodes at the same time,////if the while for the second time in this condition, then (pend_data_next - & gt; NextPtr) - & gt; NextPtr, namely the second node NextPtr to 0, while out of circulation, into the tail inserts,
}
If (p_pend_data_next==0) (OS_PEND_DATA *) {/* lowest priority tail into the TCB operation to insert is lower in prio */
P_pend_data - & gt; NextPtr=0 (OS_PEND_DATA *);//if the lowest priority, so p_pend_data_next or the last node at this time, also will become the last but one node,
//finish the footer p_pend_data who points to, its successors,////1490//p_pend_data_next his next node address is assigned to himself, it became their own next node, and footer of the next point to address 0,
//p_pend_data - & gt; NextPtr////so into the tail insertion condition satisfied
/*... Insert the at the tail. */
P_pend_data_prev=p_pend_list - & gt; TailPtr;//the previous is the purpose of these two lines operating table node is ascribed to the middle revolving pointer variable p_pend_data_prev, p_pend_data_prev became the footer, at this time also will become the last but one node,
P_pend_data - & gt; PrevPtr=p_pend_data_prev;//p_pend_data node for the lowest priority, it's a pointer to the last time before the footer, it become a footer at the same time, also the last time the tail of the node into the penultimate
//and then complete the footer p_pend_data point to who, its precursor,//
//p_pend_data - & gt; PrevPtr//
P_pend_data_prev - & gt; NextPtr=p_pend_data;//who point to complete the operation of the footer p_pend_data to assign who,//
P_pend_list - & gt; TailPtr=p_pend_data;//while no matter cycle several times, as long as acquired from the else statement does not meet the conditions of the while loop jump out, will enter the tail insert//
} else {
If (p_pend_data_next - & gt; PrevPtr==0) (OS_PEND_DATA *) {/* highest priority first insert Is new TCB highest priority? */
P_pend_data_next - & gt; PrevPtr=p_pend_data;/* Yes, insert the as the new Head of the list */
P_pend_data - & gt; PrevPtr=0 (OS_PEND_DATA *);
P_pend_data - & gt; NextPtr=p_pend_data_next;
P_pend_list - & gt; HeadPtr=p_pend_data;//while doing only once, and exit from the if statement, then will enter the first insert//
} else {/* priority comparison loop in the middle of the insert */
P_pend_data_prev=p_pend_data_next - & gt; PrevPtr;/* No, insert the in between two entries */
P_pend_data - & gt; PrevPtr=p_pend_data_prev;
P_pend_data - & gt; NextPtr=p_pend_data_next;
P_pend_data_prev - & gt; NextPtr=p_pend_data;
P_pend_data_next - & gt; PrevPtr=p_pend_data;//while do the bare minimum cycle more than once, exit from the if statement, will enter the middle insert,//
}
}
}
}
//after a while loop, waiting list will be according to the size of the priority, from high to low, string into a two-way linked list, to a system call,
//list of inserts, who want to do is this node pointer to, and who point to the node pointer assignment//operation