blob: f8bca7ad7d80b978f4438623b307eb440356f710 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/**CFile****************************************************************
FileName [reoUnits.c]
PackageName [REO: A specialized DD reordering engine.]
Synopsis [Procedures which support internal data structures.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - October 15, 2002.]
Revision [$Id: reoUnits.c,v 1.0 2002/15/10 03:00:00 alanmi Exp $]
***********************************************************************/
#include "reo.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static void reoUnitsAddToFreeUnitList( reo_man * p );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Extract the next unit from the ABC_FREE unit list.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
reo_unit * reoUnitsGetNextUnit(reo_man * p )
{
reo_unit * pUnit;
// check there are stil units to extract
if ( p->pUnitFreeList == NULL )
reoUnitsAddToFreeUnitList( p );
// extract the next unit from the linked list
pUnit = p->pUnitFreeList;
p->pUnitFreeList = pUnit->Next;
p->nUnitsUsed++;
return pUnit;
}
/**Function*************************************************************
Synopsis [Returns the unit to the ABC_FREE unit list.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void reoUnitsRecycleUnit( reo_man * p, reo_unit * pUnit )
{
pUnit->Next = p->pUnitFreeList;
p->pUnitFreeList = pUnit;
p->nUnitsUsed--;
}
/**Function*************************************************************
Synopsis [Returns the list of units to the ABC_FREE unit list.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void reoUnitsRecycleUnitList( reo_man * p, reo_plane * pPlane )
{
reo_unit * pUnit;
reo_unit * pTail = NULL; // Suppress "might be used uninitialized"
if ( pPlane->pHead == NULL )
return;
// find the tail
for ( pUnit = pPlane->pHead; pUnit; pUnit = pUnit->Next )
pTail = pUnit;
pTail->Next = p->pUnitFreeList;
p->pUnitFreeList = pPlane->pHead;
memset( pPlane, 0, sizeof(reo_plane) );
}
/**Function*************************************************************
Synopsis [Stops the unit dispenser.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void reoUnitsStopDispenser( reo_man * p )
{
int i;
for ( i = 0; i < p->nMemChunks; i++ )
ABC_FREE( p->pMemChunks[i] );
// printf("\nThe number of chunks used is %d, each of them %d units\n", p->nMemChunks, REO_CHUNK_SIZE );
p->nMemChunks = 0;
}
/**Function*************************************************************
Synopsis [Adds one unit to the list of units which constitutes the plane.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void reoUnitsAddUnitToPlane( reo_plane * pPlane, reo_unit * pUnit )
{
if ( pPlane->pHead == NULL )
{
pPlane->pHead = pUnit;
pUnit->Next = NULL;
}
else
{
pUnit->Next = pPlane->pHead;
pPlane->pHead = pUnit;
}
pPlane->statsNodes++;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void reoUnitsAddToFreeUnitList( reo_man * p )
{
int c;
// check that we still have chunks left
if ( p->nMemChunks == p->nMemChunksAlloc )
{
printf( "reoUnitsAddToFreeUnitList(): Memory manager ran out of memory!\n" );
fflush( stdout );
return;
}
// allocate the next chunk
assert( p->pUnitFreeList == NULL );
p->pUnitFreeList = ABC_ALLOC( reo_unit, REO_CHUNK_SIZE );
// split chunks into list-connected units
for ( c = 0; c < REO_CHUNK_SIZE-1; c++ )
(p->pUnitFreeList + c)->Next = p->pUnitFreeList + c + 1;
// set the last pointer to NULL
(p->pUnitFreeList + REO_CHUNK_SIZE-1)->Next = NULL;
// add the chunk to the array of chunks
p->pMemChunks[p->nMemChunks++] = p->pUnitFreeList;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|