1 /* See COPYRIGHT for copyright information. */
2 /* Kevin Klues <klueska@cs.berkeley.edu> */
9 #define POOL_TYPE_DEFINE(_type, p, sz) \
10 typedef struct struct_##p { \
18 #define POOL_INIT(p, sz) \
23 memset((p)->pool, 0, (sz) * sizeof((p)->pool[0])); \
24 for(int i=0; i<(p)->size; i++) { \
25 (p)->queue[i] = &((p)->pool[i]); \
33 rval = (p)->queue[(p)->index]; \
34 (p)->queue[(p)->index] = NULL; \
37 if((p)->index == (p)->size) { \
44 // emptyIndex is also the first element that has been allocated, iterate thru to index-1
46 #define POOL_FOR_EACH(p, func) \
48 int emptyIndex = ((p)->index + (p)->free); \
49 if (emptyIndex >= (p)->size) { \
50 emptyIndex -= (p)->size; \
52 for(int _i = emptyIndex; _i < (p)->index; _i++){ \
53 func((p)->queue[_i]); \
57 #define POOL_PUT(p, val) \
60 if((p)->free < (p)->size) { \
61 int emptyIndex = ((p)->index + (p)->free); \
62 if (emptyIndex >= (p)->size) { \
63 emptyIndex -= (p)->size; \
65 (p)->queue[emptyIndex] = val; \
72 #define POOL_EMPTY(p) ((p)->free == 0)
73 #define POOL_SIZE(p) ((p)->free)
74 #define POOL_MAX_SIZE(p) ((p)->size)
76 #endif //ROS_INC_POOL_H