4 Queue Handling Routines
6 Taken from smartall written by John Walker.
8 http://www.fourmilab.ch/smartall/
14 Bacula® - The Network Backup Solution
16 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
18 The main author of Bacula is Kern Sibbald, with contributions from
19 many others, a complete list can be found in the file AUTHORS.
20 This program is Free Software; you can redistribute it and/or
21 modify it under the terms of version three of the GNU Affero General Public
22 License as published by the Free Software Foundation and included
25 This program is distributed in the hope that it will be useful, but
26 WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 General Public License for more details.
30 You should have received a copy of the GNU Affero General Public License
31 along with this program; if not, write to the Free Software
32 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 Bacula® is a registered trademark of Kern Sibbald.
36 The licensor of Bacula is the Free Software Foundation Europe
37 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
38 Switzerland, email:ftf@fsfeurope.org.
44 /* General purpose queue */
48 struct b_queue *qnext, /* Next item in queue */
49 *qprev; /* Previous item in queue */
54 * To define a queue, use the following
56 * static BQUEUE xyz = { &xyz, &xyz };
58 * Also, note, that the only real requirement is that
59 * the object that is passed to these routines contain
60 * a BQUEUE object as the very first member. The
61 * rest of the structure may be anything.
63 * NOTE!!!! The casting here is REALLY painful, but this avoids
64 * doing ugly casting every where else in the code.
68 /* Queue manipulation functions. */
71 /* QINSERT -- Insert object at end of queue */
73 void qinsert(BQUEUE *qhead, BQUEUE *object)
75 #define qh ((BQUEUE *)qhead)
76 #define obj ((BQUEUE *)object)
78 ASSERT(qh->qprev->qnext == qh);
79 ASSERT(qh->qnext->qprev == qh);
82 obj->qprev = qh->qprev;
84 obj->qprev->qnext = obj;
90 /* QREMOVE -- Remove next object from the queue given
91 the queue head (or any item).
92 Returns NULL if queue is empty */
94 BQUEUE *qremove(BQUEUE *qhead)
96 #define qh ((BQUEUE *)qhead)
99 ASSERT(qh->qprev->qnext == qh);
100 ASSERT(qh->qnext->qprev == qh);
102 if ((object = qh->qnext) == qh)
104 qh->qnext = object->qnext;
105 object->qnext->qprev = qh;
110 /* QNEXT -- Return next item from the queue
111 * returns NULL at the end of the queue.
112 * If qitem is NULL, the first item from
113 * the queue is returned.
116 BQUEUE *qnext(BQUEUE *qhead, BQUEUE *qitem)
118 #define qh ((BQUEUE *)qhead)
119 #define qi ((BQUEUE *)qitem)
125 ASSERT(qi->qprev->qnext == qi);
126 ASSERT(qi->qnext->qprev == qi);
128 if ((object = qi->qnext) == qh)
136 /* QDCHAIN -- Dequeue an item from the middle of a queue. Passed
137 the queue item, returns the (now dechained) queue item. */
139 BQUEUE *qdchain(BQUEUE *qitem)
141 #define qi ((BQUEUE *)qitem)
143 ASSERT(qi->qprev->qnext == qi);
144 ASSERT(qi->qnext->qprev == qi);
146 return qremove(qi->qprev);