pool.h
Go to the documentation of this file.00001
00038 #ifndef STRUCT_POOL_H
00039 #define STRUCT_POOL_H
00040
00041 #include <cfg/macros.h>
00042 #include <struct/list.h>
00043
00044 #define EXTERN_POOL(name) \
00045 extern List name
00046
00047 #define DECLARE_POOL_WITH_STORAGE(name, type, num, storage) \
00048 static type name##_items[num]; \
00049 storage name; \
00050 INLINE void name##_init(void (*init_func)(type*)) \
00051 { \
00052 int i; \
00053 LIST_INIT(&name); \
00054 for (i=0;i<countof(name##_items);++i) \
00055 { \
00056 if (init_func) init_func(&name##_items[i]); \
00057 ADDTAIL(&name, (Node*)&name##_items[i]); \
00058 } \
00059 } \
00060 INLINE void name##_init(void (*init_func)(type*)) \
00061
00062
00063 #define DECLARE_POOL(name, type, num) \
00064 DECLARE_POOL_WITH_STORAGE(name, type, num, List)
00065
00066 #define DECLARE_POOL_STATIC(name, type, num) \
00067 DECLARE_POOL_WITH_STORAGE(name, type, num, static List)
00068
00069 #define pool_init(name, init_func) (*(name##_init))(init_func)
00070 #define pool_alloc(name) REMHEAD(name)
00071 #define pool_free(name, elem) ADDHEAD(name, (Node*)elem)
00072 #define pool_empty(name) ISLISTEMPTY(name)
00073
00074 #endif