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)
|
|
22 #define STAILQ_HEAD(q) ((q).head)
|
|
23 #define STAILQ_TAIL(q) ((q).tail)
|
|
24 #define STAILQ_NEXT(type, field, elm) ((elm)->field)
|
|
25 #define STAILQ_INS(q, type, field, elm) \
|
|
26 do { \
|
|
27 (elm)->field = (q).head; \
|
|
28 (q).head = elm; \
|
|
29 if((q).tail == NULL) \
|
|
30 (q).tail = elm; \
|
|
31 } while(0)
|
|
32 #define STAILQ_INS_TAIL(q, type, field, elm) \
|
|
33 do { \
|
|
34 (elm)->field = NULL; \
|
|
35 if((q).tail != NULL) \
|
|
36 (q).tail->field = elm; \
|
|
37 (q).tail = elm; \
|
|
38 if((q).head == NULL) \
|
|
39 (q).head = elm; \
|
|
40 } while(0)
|
|
41 #define STAILQ_REMOVE(q, type, field, elm) \
|
|
42 do { \
|
|
43 if((elm) == (q).head) { \
|
|
44 (q).head = (elm)->field; \
|
|
45 if((q).head == NULL) \
|
|
46 (q).tail = NULL; \
|
|
47 } else { \
|
|
48 type *_stailq_cur = (q).head; \
|
|
49 while(_stailq_cur != NULL && \
|
|
50 _stailq_cur->field != (elm)) \
|
|
51 _stailq_cur = _stailq_cur->field; \
|
|
52 if(_stailq_cur != NULL) { \
|
|
53 _stailq_cur->field = elm; \
|
|
54 if((q).tail == (elm)) \
|
|
55 (q).tail = _stailq_cur; \
|
|
56 } \
|
|
57 } \
|
|
58 } while(0)
|
|
59
|
|
60 #endif /* __TOOLS_H_ */
|