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