home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / enqueue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  2.9 KB  |  126 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: enqueue.c,v 1.9 1997/01/01 03:46:09 ldp Exp $
  4.     $Log: enqueue.c,v $
  5.     Revision 1.9  1997/01/01 03:46:09  ldp
  6.     Committed Amiga native (support) code
  7.  
  8.     Changed clib to proto
  9.  
  10.     Revision 1.8  1996/12/10 13:51:44  aros
  11.     Moved all #include's in the first column so makedepend can see it.
  12.  
  13.     Revision 1.7  1996/10/24 15:50:48  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.6  1996/10/21 20:47:07  aros
  17.     Changed struct SysBase to struct ExecBase
  18.  
  19.     Revision 1.5  1996/08/13 13:56:01  digulla
  20.     Replaced AROS_LA by AROS_LHA
  21.     Replaced some AROS_LH*I by AROS_LH*
  22.     Sorted and added includes
  23.  
  24.     Revision 1.4  1996/08/01 17:41:10  digulla
  25.     Added standard header for all files
  26.  
  27.     Desc:
  28.     Lang: english
  29. */
  30. /* I want the macros */
  31. #define AROS_ALMOST_COMPATIBLE
  32. #include "exec_intern.h"
  33. #include <exec/lists.h>
  34. #include <proto/exec.h>
  35.  
  36. /*****************************************************************************
  37.  
  38.     NAME */
  39.  
  40.     AROS_LH2I(void, Enqueue,
  41.  
  42. /*  SYNOPSIS */
  43.     AROS_LHA(struct List *, list, A0),
  44.     AROS_LHA(struct Node *, node, A1),
  45.  
  46. /*  LOCATION */
  47.     struct ExecBase *, SysBase, 45, Exec)
  48.  
  49. /*  FUNCTION
  50.     Sort a node into a list. The sort-key the field node->ln_Pri.
  51.  
  52.     INPUTS
  53.     list - Insert into this list. The list has to be in descending
  54.         order in respect to the field ln_Pri of all nodes.
  55.     node - This node is to be inserted. Note that this has to
  56.         be a complete node and not a MinNode !
  57.  
  58.     RESULT
  59.  
  60.     NOTES
  61.     The list has to be in descending order in respect to the field
  62.     ln_Pri of all nodes.
  63.  
  64.     EXAMPLE
  65.     struct List * list;
  66.     struct Node * node;
  67.  
  68.     // Sort the node at the correct place into the list
  69.     Enqueue (list, node);
  70.  
  71.     BUGS
  72.  
  73.     SEE ALSO
  74.  
  75.     INTERNALS
  76.  
  77.     HISTORY
  78.     26-08-95    digulla created after EXEC-Routine
  79.     26-10-95    digulla adjusted to new calling scheme
  80.  
  81. ******************************************************************************/
  82. {
  83.     AROS_LIBFUNC_INIT
  84.  
  85.     struct Node * next;
  86.  
  87.     assert (list);
  88.     assert (node);
  89.  
  90.     /* Look through the list */
  91.     for (next=GetHead(list); next; next=GetSucc(next))
  92.     {
  93.     /*
  94.         if the NEXT node has lower prio than the new node, insert us
  95.         before the next node
  96.     */
  97.     if (node->ln_Pri >= next->ln_Pri)
  98.     {
  99.         /* Same as insert but insert before instead of insert behind */
  100.         node->ln_Succ = next;
  101.         node->ln_Pred = next->ln_Pred;
  102.  
  103.         next->ln_Pred->ln_Succ = node;
  104.         next->ln_Pred       = node;
  105.  
  106.         /*
  107.         Done. We cannot simply break the loop because of the AddTail()
  108.         below.
  109.         */
  110.         return;
  111.     }
  112.     }
  113.  
  114.     /*
  115.     If no nodes were in the list or our node has the lowest prio,
  116.     we add it as last node
  117.     */
  118.     node->ln_Succ           = (struct Node *)&list->lh_Tail;
  119.     node->ln_Pred           = list->lh_TailPred;
  120.  
  121.     list->lh_TailPred->ln_Succ = node;
  122.     list->lh_TailPred           = node;
  123.     AROS_LIBFUNC_EXIT
  124. } /* Enqueue */
  125.  
  126.