2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Add a node into a sorted list
8 #include <exec/lists.h>
9 #include <proto/exec.h>
10 #include <aros/debug.h>
12 /*****************************************************************************
16 AROS_LH2I(void, Enqueue
,
19 AROS_LHA(struct List
*, list
, A0
),
20 AROS_LHA(struct Node
*, node
, A1
),
23 struct ExecBase
*, SysBase
, 45, Exec
)
26 Sort a node into a list. The sort-key is the field node->ln_Pri.
27 The node will be inserted into the list before the first node
28 with lower priority. This creates a FIFO queue for nodes with
32 list - Insert into this list. The list has to be in descending
33 order in respect to the field ln_Pri of all nodes.
34 node - This node is to be inserted. Note that this has to
35 be a complete node and not a MinNode !
38 The new node will be inserted before nodes with lower
42 The list has to be in descending order in respect to the field
51 // Sort the node at the correct place into the list
60 ******************************************************************************/
69 /* Look through the list */
70 ForeachNode (list
, next
)
73 Look for the first node with a lower pri as the node
74 we have to insert into the list.
76 if (node
->ln_Pri
> next
->ln_Pri
)
80 /* Insert the node before(!) next. The situation looks like this:
82 A<->next<->B *<-node->*
84 ie. next->ln_Pred points to A, A->ln_Succ points to next,
85 next->ln_Succ points to B, B->ln_Pred points to next.
86 ln_Succ and ln_Pred of node contain illegal pointers.
89 /* Let node point to A: A<-node */
90 node
->ln_Pred
= next
->ln_Pred
;
92 /* Let A point to node: A->node */
93 next
->ln_Pred
->ln_Succ
= node
;
95 /* Make next point to node: A<->node<-next<->B */
98 /* Make node point to next: A<->node->next<->B */