blob: b73a579a465fcc2e68948c743dadd61939b942ea [file] [log] [blame]
dburgess82c46ff2011-10-07 02:40:51 +00001/*
2* Copyright 2008 Free Software Foundation, Inc.
3*
4*
5* This software is distributed under the terms of the GNU Affero Public License.
6* See the COPYING file in the main directory for details.
7*
8* This use of this software may be subject to additional restrictions.
9* See the LEGAL file in the main directory for details.
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU Affero General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU Affero General Public License for more details.
20
21 You should have received a copy of the GNU Affero General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24*/
25
26
27
28
29#include "LinkedLists.h"
30
31
Pau Espin Pedrol41c68aa2018-12-03 12:35:21 +010032PointerFIFO::~PointerFIFO()
33{
34 ListNode *node, *next;
35
36 node = mHead;
37 while (node != NULL) {
38 next = node->next();
39 delete node;
40 node = next;
41 }
42
43 node = mFreeList;
44 while (node != NULL) {
45 next = node->next();
46 delete node;
47 node = next;
48 }
49}
50
kurtis.heimerl5a872472013-05-31 21:47:25 +000051void PointerFIFO::push_front(void* val) // by pat
52{
53 // Pat added this routine for completeness, but never used or tested.
54 // The first person to use this routine should remove this assert.
55 ListNode *node = allocate();
56 node->data(val);
57 node->next(mHead);
58 mHead = node;
59 if (!mTail) mTail=node;
60 mSize++;
61}
dburgess82c46ff2011-10-07 02:40:51 +000062
63void PointerFIFO::put(void* val)
64{
65 ListNode *node = allocate();
66 node->data(val);
67 node->next(NULL);
68 if (mTail!=NULL) mTail->next(node);
69 mTail=node;
70 if (mHead==NULL) mHead=node;
71 mSize++;
72}
73
74/** Take an item from the FIFO. */
75void* PointerFIFO::get()
76{
77 // empty list?
78 if (mHead==NULL) return NULL;
79 // normal case
80 ListNode* next = mHead->next();
81 void* retVal = mHead->data();
82 release(mHead);
83 mHead = next;
84 if (next==NULL) mTail=NULL;
85 mSize--;
86 return retVal;
87}
88
89
dburgess82c46ff2011-10-07 02:40:51 +000090ListNode *PointerFIFO::allocate()
91{
92 if (mFreeList==NULL) return new ListNode;
93 ListNode* retVal = mFreeList;
94 mFreeList = mFreeList->next();
95 return retVal;
96}
97
98void PointerFIFO::release(ListNode* wNode)
99{
100 wNode->next(mFreeList);
101 mFreeList = wNode;
102}