4 Queue Handling Routines
6 Taken from smartall written by John Walker.
8 http://www.fourmilab.ch/smartall/
15 Bacula® - The Network Backup Solution
17 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
19 The main author of Bacula is Kern Sibbald, with contributions from
20 many others, a complete list can be found in the file AUTHORS.
21 This program is Free Software; you can redistribute it and/or
22 modify it under the terms of version two of the GNU General Public
23 License as published by the Free Software Foundation plus additions
24 that are listed in the file LICENSE.
26 This program is distributed in the hope that it will be useful, but
27 WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 General Public License for more details.
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to the Free Software
33 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36 Bacula® is a registered trademark of John Walker.
37 The licensor of Bacula is the Free Software Foundation Europe
38 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
39 Switzerland, email:ftf@fsfeurope.org.
45 /* General purpose queue */
49 struct b_queue *qnext, /* Next item in queue */
50 *qprev; /* Previous item in queue */
55 * To define a queue, use the following
57 * static BQUEUE xyz = { &xyz, &xyz };
59 * Also, note, that the only real requirement is that
60 * the object that is passed to these routines contain
61 * a BQUEUE object as the very first member. The
62 * rest of the structure may be anything.
64 * NOTE!!!! The casting here is REALLY painful, but this avoids
65 * doing ugly casting every where else in the code.
69 /* Queue manipulation functions. */
72 /* QINSERT -- Insert object at end of queue */
74 void qinsert(BQUEUE *qhead, BQUEUE *object)
76 #define qh ((BQUEUE *)qhead)
77 #define obj ((BQUEUE *)object)
79 ASSERT(qh->qprev->qnext == qh);
80 ASSERT(qh->qnext->qprev == qh);
83 obj->qprev = qh->qprev;
85 obj->qprev->qnext = obj;
91 /* QREMOVE -- Remove next object from the queue given
92 the queue head (or any item).
93 Returns NULL if queue is empty */
95 BQUEUE *qremove(BQUEUE *qhead)
97 #define qh ((BQUEUE *)qhead)
100 ASSERT(qh->qprev->qnext == qh);
101 ASSERT(qh->qnext->qprev == qh);
103 if ((object = qh->qnext) == qh)
105 qh->qnext = object->qnext;
106 object->qnext->qprev = qh;
111 /* QNEXT -- Return next item from the queue
112 * returns NULL at the end of the queue.
113 * If qitem is NULL, the first item from
114 * the queue is returned.
117 BQUEUE *qnext(BQUEUE *qhead, BQUEUE *qitem)
119 #define qh ((BQUEUE *)qhead)
120 #define qi ((BQUEUE *)qitem)
126 ASSERT(qi->qprev->qnext == qi);
127 ASSERT(qi->qnext->qprev == qi);
129 if ((object = qi->qnext) == qh)
137 /* QDCHAIN -- Dequeue an item from the middle of a queue. Passed
138 the queue item, returns the (now dechained) queue item. */
140 BQUEUE *qdchain(BQUEUE *qitem)
142 #define qi ((BQUEUE *)qitem)
144 ASSERT(qi->qprev->qnext == qi);
145 ASSERT(qi->qnext->qprev == qi);
147 return qremove(qi->qprev);