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)
|
39
|
42 #define STAILQ_INS_AFTER(type, field, follow, elm) \
|
|
43 do { \
|
|
44 (follow)->field = (elm)->field; \
|
|
45 (elm)->field = follow; \
|
|
46 } while(0)
|
12
|
47 #define STAILQ_REMOVE(q, type, field, elm) \
|
|
48 do { \
|
|
49 if((elm) == (q).head) { \
|
|
50 (q).head = (elm)->field; \
|
|
51 if((q).head == NULL) \
|
|
52 (q).tail = NULL; \
|
|
53 } else { \
|
|
54 type *_stailq_cur = (q).head; \
|
|
55 while(_stailq_cur != NULL && \
|
|
56 _stailq_cur->field != (elm)) \
|
|
57 _stailq_cur = _stailq_cur->field; \
|
|
58 if(_stailq_cur != NULL) { \
|
|
59 _stailq_cur->field = elm; \
|
|
60 if((q).tail == (elm)) \
|
|
61 (q).tail = _stailq_cur; \
|
|
62 } \
|
|
63 } \
|
|
64 } while(0)
|
|
65
|
55
|
66
|
|
67 #define O_ALLOC(type) ((type *)malloc(sizeof(type)))
|
|
68
|
12
|
69 #endif /* __TOOLS_H_ */
|