2 * libneuro, a light weight abstraction of high or lower libraries
3 * and toolkit for applications.
4 * Copyright (C) 2005-2006 Nicholas Niro, Robert Lemay
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 * memory management system, not really performant though, its actually better
25 * to free and reallocate then trying not to free...
28 /*-------------------- Extern Headers Including --------------------*/
31 /*-------------------- Local Headers Including ---------------------*/
33 /*-------------------- Main Module Header --------------------------*/
37 /*-------------------- Other ----------------------------*/
41 POOL_AVAILABLE
= 0, /* an available spot */
42 POOL_RAWENGINE
= 1, /* RAW_ENGINE */
43 POOL_QUEUE
, /* INSTRUCTION_ENGINE */
44 /*POOL_PIXELS,*/ /* PIXEL_ENGINE */
49 /* this is the memory pool structure
50 * made to keep track of unused memory
51 * so it can be used again if necessary.
54 * this test (although working well technically) was
55 * an awful performance failure so it was dropped.
57 * the code was kept for future reference,
58 * see the macro use_memory_pool to toggle the use
61 typedef struct STRUCT_POOL
67 /*-------------------- Global Variables ----------------------------*/
69 /*-------------------- Static Variables ----------------------------*/
70 /* pool used to reuse allocated memory */
74 /*-------------------- Static Prototypes ---------------------------*/
78 /*-------------------- Static Functions ----------------------------*/
80 /*-------------------- Global Functions ----------------------------*/
82 /* function to put a new element in the pool */
84 Pool_PushData(u8 type
, void *data
)
89 /* Debug_Val(0, "Pushed a struct to be in the pool\n"); */
90 if (!Neuro_EBufIsEmpty(_pool
))
92 total
= Neuro_GiveEBufCount(_pool
) + 1;
94 /* loop the buffer to attempt to put the data
95 * into an available spot
99 tmp
= Neuro_GiveEBuf(_pool
, total
);
101 if (tmp
->type
== POOL_AVAILABLE
)
103 /* Debug_Val(0, "putting data into an available slot\n"); */
112 /* Debug_Val(0, "no more available slots, we need to allocate a new one\n"); */
114 /* if we are here, it means there was no available
115 * spot found. We will have to create a new one.
116 * and put the data in it.
118 Neuro_AllocEBuf(_pool
, sizeof(STRUCT_POOL
*), sizeof(STRUCT_POOL
));
120 tmp
= Neuro_GiveCurEBuf(_pool
);
127 /* returns a pointer corresponding to the type or
131 Pool_PullData(u8 type
)
137 if (Neuro_EBufIsEmpty(_pool
))
140 total
= Neuro_GiveEBufCount(_pool
) + 1;
144 tmp
= Neuro_GiveEBuf(_pool
, total
);
146 if (tmp
->type
== type
)
148 tmp
->type
= POOL_AVAILABLE
;
158 /*-------------------- Poll ----------------------------------------*/
166 /*-------------------- Constructor Destructor ----------------------*/
171 Neuro_CreateEBuf(&_pool
);
178 Neuro_CleanEBuf(&_pool
);