2010-01-14 Marek Safar <marek.safar@gmail.com>
[mono.git] / mono / metadata / mempool-internals.h
1 #ifndef _MONO_MEMPOOL_INTERNALS_H_
2 #define _MONO_MEMPOOL_INTERNALS_H_
3
4 #include <glib.h>
5
6 #include "mono/utils/mono-compiler.h"
7
8 static inline GList*
9 g_list_prepend_mempool (MonoMemPool *mp, GList *list, gpointer data)
10 {
11         GList *new_list;
12         
13         new_list = mono_mempool_alloc (mp, sizeof (GList));
14         new_list->data = data;
15         new_list->prev = list ? list->prev : NULL;
16     new_list->next = list;
17
18     if (new_list->prev)
19             new_list->prev->next = new_list;
20     if (list)
21             list->prev = new_list;
22
23         return new_list;
24 }
25
26 static inline GSList*
27 g_slist_prepend_mempool (MonoMemPool *mp, GSList *list, gpointer  data)
28 {
29         GSList *new_list;
30         
31         new_list = mono_mempool_alloc (mp, sizeof (GSList));
32         new_list->data = data;
33         new_list->next = list;
34
35         return new_list;
36 }
37
38 static inline GSList*
39 g_slist_append_mempool (MonoMemPool *mp, GSList *list, gpointer data)
40 {
41         GSList *new_list;
42         GSList *last;
43
44         new_list = mono_mempool_alloc (mp, sizeof (GSList));
45         new_list->data = data;
46         new_list->next = NULL;
47
48         if (list) {
49                 last = list;
50                 while (last->next)
51                         last = last->next;
52                 last->next = new_list;
53
54                 return list;
55         } else
56                 return new_list;
57 }
58
59 long
60 mono_mempool_get_bytes_allocated (void) MONO_INTERNAL;
61
62 #endif