home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_12 / 9n12032a < prev    next >
Text File  |  1991-10-15  |  2KB  |  57 lines

  1. ---------------------------------------------------
  2.  
  3. FUNCTION LOCATE_NODE: The steps to locating a node in the list are:
  4.  
  5. A. Make one cycle of the list starting at the root. Since process idle
  6.    has priority zero and the user cannot add nodes with a priority less
  7.    than 1, the idle node is always the last one in the cycle.
  8.  
  9. B. If the priority we are searching for is equal to the current 
  10.    entry's, return the previous entry's address.
  11.  
  12. C. Else if the new priority is greater than that in the list the one we 
  13.    are searching for isn't in the list. So is we were looking for
  14.    an exact match indicate it wasn't found. For an inexact match
  15.    return the address of the previous node (which must be greater than
  16.    the one we are searching for).
  17.  
  18. D. The match may still be coming so keep looking.
  19.  
  20. E. We've reached the end of the list so is we were looking for
  21.    an exact match indicate it wasn't found. For an inexact match
  22.    return the address of the previous node (which must be greater than
  23.    the one we are searching for).
  24.     
  25. -------------------------------------------------------------- */
  26.     
  27. Node *locate_node(unsigned priority, int match)
  28. {
  29.     const Node *pnode = proot_node;
  30.  
  31. /*A*/    while (pnode->process != idle) {
  32. /*B*/        if (priority == pnode->priority) {
  33.             return pnode->pbwd;
  34.         }
  35. /*C*/        else if (priority > pnode->priority) {
  36.             if (match == EXACT) {
  37.                 return NULL;
  38.         }
  39.             else {
  40.                 return pnode->pbwd;
  41.             }
  42.         }
  43. /*D*/        else {
  44.             pnode = pnode->pfwd;
  45.         }
  46.     }
  47.  
  48. /*E*/    if (match == EXACT) {
  49.         return NULL;
  50.     }
  51.     else {
  52.         return pnode->pbwd;
  53.     }
  54. }
  55.  
  56.  
  57.