blob: ba0f0ccba8d58d4ce5f31e5d81b4d4f60245aa28 [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
32
33
34void PointerFIFO::put(void* val)
35{
36 ListNode *node = allocate();
37 node->data(val);
38 node->next(NULL);
39 if (mTail!=NULL) mTail->next(node);
40 mTail=node;
41 if (mHead==NULL) mHead=node;
42 mSize++;
43}
44
45/** Take an item from the FIFO. */
46void* PointerFIFO::get()
47{
48 // empty list?
49 if (mHead==NULL) return NULL;
50 // normal case
51 ListNode* next = mHead->next();
52 void* retVal = mHead->data();
53 release(mHead);
54 mHead = next;
55 if (next==NULL) mTail=NULL;
56 mSize--;
57 return retVal;
58}
59
60
61
62ListNode *PointerFIFO::allocate()
63{
64 if (mFreeList==NULL) return new ListNode;
65 ListNode* retVal = mFreeList;
66 mFreeList = mFreeList->next();
67 return retVal;
68}
69
70void PointerFIFO::release(ListNode* wNode)
71{
72 wNode->next(mFreeList);
73 mFreeList = wNode;
74}
75
76
77