landqueue.c

Go to the documentation of this file.
00001 
00002 /*  $Id: landqueue.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "landinternal.h"
00032 
00033 
00034 
00035 typedef struct tyqueuerecord {
00036     
00037     Handle hdata;
00038     
00039     struct tyqueuerecord **hnext;
00040     } tyqueuerecord, *ptrqueuerecord, **hdlqueuerecord;
00041 
00042 
00043 boolean landpushqueue (Handle h) {
00044     
00045     /*
00046     implement a first-in-first-out queue.  push a new element at the end
00047     of the list headed bu by (**landglobals).hqueue.
00048     */
00049     
00050     register hdllandglobals hg = landgetglobals ();
00051     register hdlqueuerecord x;
00052     register hdlqueuerecord hlast = nil;
00053     register short queuedepth = 0;
00054     hdlqueuerecord hnew;
00055     tyqueuerecord q;
00056     
00057     q.hdata = h;
00058     
00059     q.hnext = nil;
00060     
00061     if (!landnewfilledhandle (&q, longsizeof (tyqueuerecord), (Handle *) &hnew))
00062         return (false);
00063     
00064     x = (hdlqueuerecord) (**hg).hqueue;
00065     
00066     if (x == nil) { /*inserting into empty queue*/
00067         
00068         (**hg).hqueue = (Handle) hnew;
00069         
00070         return (true);
00071         }
00072         
00073     while (x != nil) { /*find the last guy in the queue*/
00074         
00075         hlast = x;
00076         
00077         x = (**x).hnext;
00078         
00079         queuedepth++;
00080         } /*while*/
00081     
00082     (**hlast).hnext = hnew;
00083     
00084     if (queuedepth > (**hg).maxqueuedepth) /*for display in stats window*/
00085         (**hg).maxqueuedepth = queuedepth;
00086     
00087     return (true);
00088     } /*landpushqueue*/
00089 
00090 
00091 boolean landpopqueue (Handle *h) {
00092     
00093     /*
00094     pop the first guy off the queue, returning the data saved in h.
00095     
00096     return false if the queue is empty.
00097     */
00098     
00099     register hdllandglobals hg = landgetglobals ();
00100     register hdlqueuerecord x = (hdlqueuerecord) (**hg).hqueue;
00101     
00102     if (x == nil) /*empty queue*/
00103         return (false);
00104     
00105     *h = (**x).hdata; /*return the first guy on the queue*/
00106     
00107     (**hg).hqueue = (Handle) (**x).hnext;
00108     
00109     landdisposehandle ((Handle) x);
00110     
00111     return (true);
00112     } /*landpopqueue*/
00113 
00114 
00115 boolean landpopqueueitem (landqueuepopcallback cb, long refcon, Handle *h) {
00116     
00117     /*
00118     scan the queue for the item that satisfies the callback
00119     
00120     if found, pop it out and return true; else return false.  
00121     */
00122     
00123     register hdlqueuerecord x;
00124     register hdlqueuerecord hnext;
00125     register hdlqueuerecord hprev = nil;
00126     register hdllandglobals hg = landgetglobals ();
00127     
00128     x = (hdlqueuerecord) (**hg).hqueue;
00129     
00130     while (x != nil) { /*haven't reached end of queue*/
00131         
00132         hnext = (**x).hnext;
00133         
00134         if ((*cb) ((**x).hdata, refcon)) { /*found it*/
00135             
00136             *h = (**x).hdata;
00137             
00138             if (hprev == nil) /*was first in queue*/
00139                 (**hg).hqueue = (Handle) hnext;
00140             else
00141                 (**hprev).hnext = hnext;
00142             
00143             landdisposehandle ((Handle) x);
00144             
00145             return (true);
00146             }
00147         
00148         hprev = x;
00149         
00150         x = hnext;
00151         }
00152     
00153     return (false); /*didn't find it*/
00154     } /*landpopqueueitem*/
00155 
00156 
00157 boolean landemptyqueue (void) {
00158     
00159     /*
00160     empty out the queue, return true if it was non-empty.
00161     */
00162     
00163     register boolean fl = false;
00164     Handle h;
00165     
00166     while (landpopqueue (&h))
00167         fl = true;
00168         
00169     return (fl);
00170     } /*landemptyqueue*/
00171 
00172 
00173 

Generated on Wed May 31 18:19:50 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6