pool.h

Go to the documentation of this file.
00001 
00039 /*#*
00040  *#* $Log$
00041  *#* Revision 1.6  2006/07/19 12:56:28  bernie
00042  *#* Convert to new Doxygen style.
00043  *#*
00044  *#* Revision 1.5  2005/11/04 16:20:02  bernie
00045  *#* Fix reference to README.devlib in header.
00046  *#*
00047  *#* Revision 1.4  2005/04/11 19:10:28  bernie
00048  *#* Include top-level headers from cfg/ subdir.
00049  *#*
00050  *#* Revision 1.3  2004/12/08 08:09:01  bernie
00051  *#* Add missing header.
00052  *#*
00053  *#*/
00054 #ifndef MWARE_POOL_H
00055 #define MWARE_POOL_H
00056 
00057 #include <cfg/macros.h>
00058 #include <mware/list.h>
00059 
00060 #define EXTERN_POOL(name) \
00061     extern List name
00062 
00063 #define DECLARE_POOL_WITH_STORAGE(name, type, num, storage) \
00064     static type name##_items[num]; \
00065     storage name; \
00066     INLINE void name##_init(void (*init_func)(type*)) \
00067     { \
00068         int i; \
00069         LIST_INIT(&name); \
00070         for (i=0;i<countof(name##_items);++i) \
00071         { \
00072             if (init_func) init_func(&name##_items[i]); \
00073             ADDTAIL(&name, (Node*)&name##_items[i]); \
00074         } \
00075     } \
00076     INLINE void name##_init(void (*init_func)(type*)) \
00077     
00078 
00079 #define DECLARE_POOL(name, type, num) \
00080     DECLARE_POOL_WITH_STORAGE(name, type, num, List)
00081 
00082 #define DECLARE_POOL_STATIC(name, type, num) \
00083     DECLARE_POOL_WITH_STORAGE(name, type, num, static List)
00084 
00085 #define pool_init(name, init_func)     (*(name##_init))(init_func)
00086 #define pool_alloc(name)               REMHEAD(name)
00087 #define pool_free(name, elem)          ADDHEAD(name, (Node*)elem)
00088 #define pool_empty(name)               ISLISTEMPTY(name)
00089 
00090 #endif /* MWARE_POOL_H */