Problemas com os relocs
[pspdecompiler.git] / llist.c
blobd7cbfa6bb6fd3cfc466a6f320679056d3893faf6
2 #include <stdlib.h>
4 #include "llist.h"
5 #include "utils.h"
7 #define LLIST_ALLOC_SIZE 4096
9 struct _llist_pool {
10 llist free;
11 llist allocated;
14 llist_pool llist_create (void)
16 llist_pool result = (llist_pool) xmalloc (sizeof (struct _llist_pool));
17 result->free = NULL;
18 result->allocated = NULL;
19 return result;
22 void llist_destroy (llist_pool pool)
24 llist el, ne;
25 for (el = pool->allocated; el; el = ne) {
26 ne = el->next;
27 free (el);
29 pool->free = NULL;
30 pool->allocated = NULL;
31 free (pool);
35 llist llist_alloc (llist_pool pool)
37 llist l;
38 if (!pool->free) {
39 int i;
40 l = (llist) xmalloc (LLIST_ALLOC_SIZE * sizeof (struct _llist));
41 l->next = pool->allocated;
42 pool->allocated = l;
43 for (i = 1; i < LLIST_ALLOC_SIZE - 1; i++) {
44 l[i].next = &l[i + 1];
46 l[i].next = NULL;
47 pool->free = &l[1];
49 l = pool->free;
50 pool->free = l->next;
51 return l;
54 llist llist_add (llist_pool pool, llist l, void *val)
56 llist el = llist_alloc (pool);
57 el->value = val;
58 el->next = l;
59 return el;
62 void llist_free (llist_pool pool, llist el)
64 el->next = pool->free;
65 pool->free = el;
68 void llist_freeall (llist_pool pool, llist l)
70 llist nl;
71 while (l) {
72 nl = l->next;
73 l->next = pool->free;
74 pool->free = l;
75 l = nl;