summaryrefslogtreecommitdiff
path: root/legacy/evas/src/lib/main.c
diff options
context:
space:
mode:
authordoursse <doursse>2008-07-10 16:38:54 +0000
committerdoursse <doursse@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>2008-07-10 16:38:54 +0000
commit9b35bc26f31219887d0c4344261bdd79bb8c22b2 (patch)
tree2bf252f9b29e4f4676508a3d46cb59d9398b1536 /legacy/evas/src/lib/main.c
parent11a6fd276c8a637469e9846fef47947421040688 (diff)
* move evas_mempool from main.c to it's own file in data/ as it's only
used by evas_list * add a header files for evas_cache, evas_path and evas_module * remove trailing spaces in evas_list.c SVN revision: 35052
Diffstat (limited to '')
-rw-r--r--legacy/evas/src/lib/main.c181
1 files changed, 0 insertions, 181 deletions
diff --git a/legacy/evas/src/lib/main.c b/legacy/evas/src/lib/main.c
index 07cd789601..3578cc40af 100644
--- a/legacy/evas/src/lib/main.c
+++ b/legacy/evas/src/lib/main.c
@@ -207,184 +207,3 @@ evas_debug_magic_string_get(DATA32 magic)
207 }; 207 };
208 return "<UNKNOWN>"; 208 return "<UNKNOWN>";
209} 209}
210
211
212
213
214
215
216
217
218//#define NOPOOL
219
220typedef struct _Pool Pool;
221
222struct _Pool
223{
224 int usage;
225 void *base;
226 Pool *prev, *next;
227};
228
229Pool *
230_evas_mp_pool_new(Evas_Mempool *pool)
231#ifdef NOPOOL
232{
233 static Pool thepool;
234 return &thepool;
235}
236#else
237{
238 Pool *p;
239 void **ptr;
240 int item_alloc, i;
241
242 item_alloc = ((pool->item_size + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *);
243 p = malloc(sizeof(Pool) + (pool->pool_size * item_alloc));
244 ptr = (void **)(((unsigned char *)p) + sizeof(Pool));
245 p->usage = 0;
246 p->base = ptr;
247 for (i = 0; i < pool->pool_size - 1; i++)
248 {
249 *ptr = (void **)(((unsigned char *)ptr) + item_alloc);
250 ptr = *ptr;
251 }
252 *ptr = NULL;
253 return p;
254}
255#endif
256
257void
258_evas_mp_pool_free(Pool *p)
259#ifdef NOPOOL
260{
261}
262#else
263{
264 free(p);
265}
266#endif
267
268void *
269evas_mempool_malloc(Evas_Mempool *pool, int size)
270#ifdef NOPOOL
271{
272 return malloc(size);
273}
274#else
275{
276 Pool *p;
277 void *mem;
278
279 for (p = pool->first; p; p = p->next) // look 4 pool from 2nd bucket on
280 {
281 if (p->base) // base is not NULL - has a free slot
282 {
283 if (p->prev)
284 {
285 if (pool->last == p) pool->last = p->prev;
286 p->prev->next = p->next;
287 p->prev = NULL;
288 p->next = pool->first;
289 p->next->prev = p;
290 pool->first = p;
291 }
292 break;
293 }
294 }
295 if (!p) // we have reached the end of the list - no free pools
296 {
297 p = _evas_mp_pool_new(pool);
298 if (!p) return NULL;
299 p->prev = NULL;
300 p->next = pool->first;
301 if (p->next) p->next->prev = p;
302 if (!pool->last) pool->last = p;
303 pool->first = p;
304 }
305 mem = p->base; // this points to the next free block - so take it
306 p->base = *((void **)mem); // base now points to the next free block
307 if (!p->base) // move to end - it just filled up
308 {
309 if (p->next)
310 {
311 if (p->prev) p->prev->next = p->next;
312 else pool->first = p->next;
313 p->next->prev = p->prev;
314 ((Pool *)pool->last)->next = p;
315 p->prev = pool->last;
316 p->next = NULL;
317 pool->last = p;
318 }
319 }
320 p->usage++;
321 pool->usage++;
322 return mem;
323}
324#endif
325
326void
327evas_mempool_free(Evas_Mempool *pool, void *ptr)
328#ifdef NOPOOL
329{
330 free(ptr);
331}
332#else
333{
334 Pool *p;
335 void *pmem;
336 int item_alloc, psize;
337
338 item_alloc = ((pool->item_size + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *);
339 psize = item_alloc * pool->pool_size;
340 for (p = (Pool *)(pool->first); p; p = p->next) // look 4 pool
341 {
342 pmem = (void *)(((unsigned char *)p) + sizeof(Pool)); // pool mem base
343 if ((ptr >= pmem) && ((unsigned char *)ptr < (((unsigned char *)pmem) + psize))) // is it in pool mem?
344 {
345 *((void **)ptr) = p->base; // freed node points to prev free node
346 p->base = ptr; // next free node is now the one we freed
347 p->usage--;
348 pool->usage--;
349 if (p->usage == 0) // free bucket
350 {
351 if (p->prev) p->prev->next = p->next;
352 if (p->next) p->next->prev = p->prev;
353 if (pool->last == p) pool->last = p->prev;
354 if (pool->first == p) pool->first = p->next;
355 _evas_mp_pool_free(p);
356 }
357 else
358 {
359 if (p->prev) // if not the first - move to front
360 {
361 p->prev->next = p->next;
362 if (p->next) p->next->prev = p->prev;
363 if (pool->last == p) pool->last = p->prev;
364 p->prev = NULL;
365 p->next = pool->first;
366 p->next->prev = p;
367 pool->first = p;
368 }
369 }
370 break;
371 }
372 }
373}
374#endif
375
376void *
377evas_mempool_calloc(Evas_Mempool *pool, int size)
378#ifdef NOPOOL
379{
380 return calloc(1, size);
381}
382#else
383{
384 void *mem;
385
386 mem = evas_mempool_malloc(pool, size);
387 memset(mem, 0, size);
388 return mem;
389}
390#endif