Reordering lists

Lists can be reordered in the following two ways. The method you choose depends on the situation.

  • Reorder manually using the functions described in Section 6.6 to remove entities from their current position and place them in their desired position.
  • Reorder by calling function cssols to sort the list using the given ordering function.

When you order lists manually, you should realize that the functions to remove entities from lists and the functions to add entities to lists change the statistics of the list. This is usually not a problem for lists that are used as a holding place for an indeterminate number of entities since statistics are usually not needed or collected for these lists. It is a problem for lists representing queues because queue statistics can be useful for analysis and decision making. Statistics are almost always kept for lists representing queues. When manually ordering lists you should temporarily disable statistics. You can use the functions in the table below to disable and enable statistics.

Function Description
csdsst Disable statistics collection.
csenst Enable statistics collection for a list.

You need not disable or enable statistics collection when using cssols to reorder a list because cssols automatically maintains statistics.

An example of manually reordering a list is the selection rule given below that moves the first acceptable request to the top of the list. The function loops through the request list until either an acceptable request is found or the end of the list is reached. If the end of the list is reached and no suitable request is found, the function returns a zero. If a request is found, the statistics are disabled using function csdsst, the acceptable request is removed from the list using function csgpls to remove it by pointer, and then it is inserted at the head of the list using function cspols with a one time ordering of LIFO. Finally, the statistics are enabled using function csenst and a value of one returned to indicate successful completion.


int selfun(RESRC *rp)
{
   RREQ *rqp;
   int accept();
   CSOBSST *os;
   CSTIMST *ts;

   for (rqp = (RREQ *)csfsls(rp->rsrqls));
     rqp != NULL && (!accept(rqp));
     rqp = (RREQ *)csnxls(CSENTITY* rqp);

   /* If no acceptable request is found... */

   if (rqp == NULL)
   {
     return(0);
   }
   csdsst(rp->rsrqls, &ts, &os);
   csgpls(rp->rsrpls, rqp);
   cspols(rprsqls, rqp, CSLIFO, NULL);
   csenst(rp->rsrqls, ts, os);
   return(1);
}

If you had wanted to sort the whole list rather than move one entity to the top, it would have been much easier to use the function cssols. Sorting a whole list manually would require you to implement some type of sorting algorithm.