libsrc/queue.cxx

Go to the documentation of this file.
00001 /**********************************************************************
00002  * Copyright 2002 Jeff Rush <jrush@taupro.com>
00003  * Original Copyright 1979-2002 Udanax.com
00004  *
00005  * This file is part of the Udanax xanalogical storage system.
00006  *
00007  * Udanax is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * Udanax is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with Udanax; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  **********************************************************************/
00021 
00030 /* Modification History:
00031  * $Log: queue.cxx,v $
00032  * Revision 1.6  2004/09/04 16:02:18  jrush
00033  * Added Doxygen headers before each and every function definition.
00034  *
00035  * Revision 1.5  2004/09/04 13:13:55  jrush
00036  * Added Doxygen commenting around functions.
00037  *
00038  * Revision 1.4  2002/07/14 08:28:33  jrush
00039  * Rearranged unused functions
00040  *
00041  * Revision 1.3  2002/05/28 04:22:29  jrush
00042  * Adjusted source files to comply with GPL licensing.
00043  *
00044  * Revision 1.2  2002/05/28 02:51:11  jrush
00045  * Made static any functions and global variables private to this source file
00046  * and commented out any unused functions.
00047  *
00048  * Revision 1.1  2002/04/12 11:50:24  jrush
00049  * Renamed queues.cxx to queue.cxx, to reflect renaming of corresponding
00050  * include file.
00051  *
00052  * Revision 1.3  2002/04/06 19:51:30  jrush
00053  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00054  *
00055  * Revision 1.2  2002/02/14 09:27:43  jrush
00056  * Cleaned up source:
00057  *
00058  * 1. ran thru the indent tool to achieve a standard look,
00059  * 2. added structured comments at top for use with DOxygen reporting
00060  *    as well as CVS keywords,
00061  * 3. fixed compiler warnings re ambiguous assign/compares,
00062  *    needed casts and unused/uninitialized variables,
00063  * 4. fixed funcs that didn't specify a return type,
00064  * 5. centralized prototypes in protos.h, removing incomplete ones,
00065  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00066  * 7. fixed initializer nesting in tumbler constants,
00067  * 8. renamed vars that conflict with C++ keywords (new, this),
00068  * 9. fixed global/extern confusion re some global vars.
00069  *
00070  */
00071 
00072 /* 
00073  * 
00074  * Queue manipulation routines
00075  * 
00076  * Designed and implemented by John Walker in January 1986
00077  * 
00078  * Derived from the Masterstroke multitasking process scheduler, and before
00079  * that the Marinchip NOS/MT scheduler, the Marinchip Disc Executive kernel,
00080  * the ISD Interactive Network real time operating system, the FANG task
00081  * handler, and CHI/OS.
00082  * 
00083  */
00084 
00085 #define I_LEVEL 1
00086 #include "udanax.h"
00087 
00088 /* QINIT -- Initialise links for null queue */
00089 
00097     void
00098 qinit(
00099     struct queue *qhead)
00100 {
00101     qhead->qnext = qhead->qprev = qhead;
00102 }
00103 
00104 /* QPUSH -- Push object at start of queue */
00105 
00113     void
00114 qpush(
00115     struct queue *qhead,
00116     struct queue *object)
00117 {
00118     assert(qhead->qprev->qnext == qhead);
00119     assert(qhead->qnext->qprev == qhead);
00120 
00121     object->qprev        = qhead;
00122     object->qnext        = qhead->qnext;
00123     qhead->qnext         = object;
00124     object->qnext->qprev = object;
00125 }
00126 
00127 /* QREMOVE -- Remove object from queue.  Returns NULL if queue empty */
00128 
00136     struct queue *
00137 qremove(
00138     struct queue *qhead)
00139 {
00140     struct queue *object;
00141 
00142     assert(qhead->qprev->qnext == qhead);
00143     assert(qhead->qnext->qprev == qhead);
00144 
00145     if ((object = qhead->qnext) == qhead)
00146         return NULL;
00147 
00148     qhead->qnext         = object->qnext;
00149     object->qnext->qprev = qhead;
00150 
00151     return object;
00152 }
00153 
00154 /* QNEXT -- Get next object from queue nondestructively. Returns NULL at end of queue */
00155 
00163     queue *
00164 queue::next(
00165     queue *qhead)
00166 {
00167     struct queue *object = this->qnext;
00168 
00169     if (object == qhead)
00170         object = NULL;
00171 
00172     return object;
00173 }
00174 
00175 /* QLENGTH -- Return number of items on queue, zero if queue empty. Note that this must traverse all the links of the
00176  * queue, so if all you're testing is whether the queue is empty or not, you should use the qempty(queue) macro
00177  * (defined in queues.h) which uses qnext() to detect an empty queue much faster. */
00178 
00186     int
00187 qlength(
00188     struct queue *qhead)
00189 {
00190     struct queue *qp;
00191 
00192     int l = 0;
00193     qp = qhead->qnext;
00194 
00195     while (qp != qhead) {
00196         l++;
00197         qp = qp->qnext;
00198     }
00199     return l;
00200 }

Generated on Sun Aug 21 04:18:14 2005 for Udanax-Green by doxygen1.3.4