2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Bacula fifo list routines
22 * flist is a simple malloc'ed array of pointers. Derived from alist.
24 * Kern Sibbald, August 2014
30 void *flist::dequeue()
38 item = items[get_item];
39 items[get_item++] = NULL;
40 if (get_item >= max_items) {
48 * Queue an item to the list
50 bool flist::queue(void *item)
52 if (num_items == max_items) {
56 items[add_item++] = item;
57 if (add_item >= max_items) {
63 /* Destroy the list and its contents */
66 if (num_items && own_items) {
67 for (int i=0; i<num_items; i++) {
85 int main(int argc, char *argv[])
93 fileset = (FILESET *)malloc(sizeof(FILESET));
94 bmemzero(fileset, sizeof(FILESET));
95 fileset->mylist.init();
97 printf("Manual allocation/destruction of list:\n");
99 for (i=0; i<20; i++) {
100 sprintf(buf, "This is item %d", i);
102 if (fileset->mylist.queue(p)) {
103 printf("Added item = %s\n", p);
105 q = (char *)fileset->mylist.dequeue();
106 printf("Dequeue item = %s\n", q);
108 if (fileset->mylist.queue(p)) {
109 printf("Added item = %s\n", p);
111 printf("Big problem could not queue item %d %s\n", i, p);
115 while ((q=(char *)fileset->mylist.dequeue())) {
116 printf("Dequeue item = %s\n", q);
119 for (i=1; !fileset->mylist.empty(); i++) {
120 q = (char *)fileset->mylist.dequeue();
124 printf("Item %d = %s\n", i, q);
127 fileset->mylist.destroy();
130 printf("Allocation/destruction using new delete\n");
131 mlist = New(flist(10));
133 for (i=0; i<20; i++) {
134 sprintf(buf, "This is item %d", i);
136 if (!mlist->queue(p)) {
141 for (i=1; !mlist->empty(); i++) {
142 p = (char *)mlist->dequeue();
143 printf("Item %d = %s\n", i, p);
149 sm_dump(false); /* test program */