home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / lists / src / enqueue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.3 KB  |  104 lines

  1. /*
  2.     (C) 1995 AROS - The Amiga Replacement OS
  3.     $Id: enqueue.c 1.1 1995/11/05 22:49:09 digulla Exp digulla $
  4.     $Log: enqueue.c $
  5.  * Revision 1.1  1995/11/05  22:49:09  digulla
  6.  * Initial revision
  7.  *
  8.     Desc:
  9.     Lang: english
  10. */
  11. /* I want the macros */
  12. #define AROS_ALMOST_COMPATIBLE
  13. #include "exec_intern.h"
  14.  
  15. /*****************************************************************************
  16.  
  17.     NAME */
  18.     #include <exec/lists.h>
  19.     #include <clib/exec_protos.h>
  20.  
  21.     __AROS_LH2I(void, Enqueue,
  22.  
  23. /*  SYNOPSIS */
  24.     __AROS_LA(struct List *, list, A0),
  25.     __AROS_LA(struct Node *, node, A1),
  26.  
  27. /*  LOCATION */
  28.     struct SysBase *, SysBase, 45, Exec)
  29.  
  30. /*  FUNCTION
  31.     Sort a node into a list. The sort-key the field node->ln_Pri.
  32.  
  33.     INPUTS
  34.     list - Insert into this list. The list has to be in descending
  35.         order in respect to the field ln_Pri of all nodes.
  36.     node - This node is to be inserted. Note that this has to
  37.         be a complete node and not a MinNode !
  38.  
  39.     RESULT
  40.  
  41.     NOTES
  42.     The list has to be in descending order in respect to the field
  43.     ln_Pri of all nodes.
  44.  
  45.     EXAMPLE
  46.     struct List * list;
  47.     struct Node * node;
  48.  
  49.     // Sort the node at the correct place into the list
  50.     Enqueue (list, node);
  51.  
  52.     BUGS
  53.  
  54.     SEE ALSO
  55.  
  56.     INTERNALS
  57.  
  58.     HISTORY
  59.     26-08-95    digulla created after EXEC-Routine
  60.     26-10-95    digulla adjusted to new calling scheme
  61.  
  62. ******************************************************************************/
  63. {
  64.     struct Node * next;
  65.  
  66.     assert (list);
  67.     assert (node);
  68.  
  69.     /* Look through the list */
  70.     for (next=GetHead(list); next; next=GetSucc(next))
  71.     {
  72.     /*
  73.         if the NEXT node has lower prio than the new node, insert us
  74.         before the next node
  75.     */
  76.     if (node->ln_Pri >= next->ln_Pri)
  77.     {
  78.         /* Same as insert but insert before instead of insert behind */
  79.         node->ln_Succ = next;
  80.         node->ln_Pred = next->ln_Pred;
  81.  
  82.         next->ln_Pred->ln_Succ = node;
  83.         next->ln_Pred       = node;
  84.  
  85.         /*
  86.         Done. We cannot simly break the loop because of the AddTail()
  87.         below.
  88.         */
  89.         return;
  90.     }
  91.     }
  92.  
  93.     /*
  94.     If no nodes were in the list or our node has the lowest prio,
  95.     we add it as last node
  96.     */
  97.     node->ln_Succ           = (struct Node *)&list->lh_Tail;
  98.     node->ln_Pred           = list->lh_TailPred;
  99.  
  100.     list->lh_TailPred->ln_Succ = node;
  101.     list->lh_TailPred           = node;
  102. } /* Enqueue */
  103.  
  104.