12
|
1 #ifndef __TOOLS_H_
|
|
2 #define __TOOLS_H_
|
|
3
|
|
4
|
|
5 typedef struct _elmpool elmpool_t;
|
|
6
|
|
7 extern elmpool_t *elmpool_new(int elm_sz, int inc_num);
|
|
8 extern void *elmpool_elm_alloc(elmpool_t *pool);
|
|
9 extern void elmpool_elm_free(elmpool_t *pool, void *elm);
|
|
10 extern void elmpool_free(elmpool_t *pool);
|
|
11
|
|
12
|
|
13 #define STAILQ(type) \
|
|
14 struct { \
|
|
15 type *head; \
|
|
16 type *tail; \
|
|
17 }
|
|
18 #define STAILQ_INIT(q) \
|
|
19 do { \
|
|
20 (q).head = (q).tail = NULL; \
|
|
21 } while(0)
|
13
|
22 #define STAILQ_CLEAN(q) STAILQ_INIT(q)
|
12
|
23 #define STAILQ_HEAD(q) ((q).head)
|
|
24 #define STAILQ_TAIL(q) ((q).tail)
|
|
25 #define STAILQ_NEXT(type, field, elm) ((elm)->field)
|
|
26 #define STAILQ_INS(q, type, field, elm) \
|
|
27 do { \
|
|
28 (elm)->field = (q).head; \
|
|
29 (q).head = elm; \
|
|
30 if((q).tail == NULL) \
|
|
31 (q).tail = elm; \
|
|
32 } while(0)
|
|
33 #define STAILQ_INS_TAIL(q, type, field, elm) \
|
|
34 do { \
|
|
35 (elm)->field = NULL; \
|
|
36 if((q).tail != NULL) \
|
|
37 (q).tail->field = elm; \
|
|
38 (q).tail = elm; \
|
|
39 if((q).head == NULL) \
|
|
40 (q).head = elm; \
|
|
41 } while(0)
|
|
42 #define STAILQ_REMOVE(q, type, field, elm) \
|
|
43 do { \
|
|
44 if((elm) == (q).head) { \
|
|
45 (q).head = (elm)->field; \
|
|
46 if((q).head == NULL) \
|
|
47 (q).tail = NULL; \
|
|
48 } else { \
|
|
49 type *_stailq_cur = (q).head; \
|
|
50 while(_stailq_cur != NULL && \
|
|
51 _stailq_cur->field != (elm)) \
|
|
52 _stailq_cur = _stailq_cur->field; \
|
|
53 if(_stailq_cur != NULL) { \
|
|
54 _stailq_cur->field = elm; \
|
|
55 if((q).tail == (elm)) \
|
|
56 (q).tail = _stailq_cur; \
|
|
57 } \
|
|
58 } \
|
|
59 } while(0)
|
|
60
|
|
61 #endif /* __TOOLS_H_ */
|