1 #ifndef ASTERISK_LINKEDLISTS_H
2 #define ASTERISK_LINKEDLISTS_H
4 #include <asterisk/lock.h>
6 #define AST_LIST_LOCK(head) \
7 ast_mutex_lock(&(head)->lock)
9 #define AST_LIST_UNLOCK(head) \
10 ast_mutex_unlock(&(head)->lock)
12 #define AST_LIST_HEAD(name, type) \
18 #define AST_LIST_HEAD_SET(head,entry) do { \
19 (head)->first=(entry); \
20 ast_pthread_mutex_init(&(head)->lock,NULL); \
23 #define AST_LIST_ENTRY(type) \
28 #define AST_LIST_FIRST(head) ((head)->first)
30 #define AST_LIST_NEXT(elm, field) ((elm)->field.next)
32 #define AST_LIST_EMPTY(head) (AST_LIST_FIRST(head) == NULL)
34 #define AST_LIST_TRAVERSE(head,var,field) \
35 for((var) = (head)->first; (var); (var) = (var)->field.next)
37 #define AST_LIST_HEAD_INIT(head) { \
38 (head)->first = NULL; \
39 ast_pthread_mutex_init(&(head)->lock,NULL); \
42 #define AST_LIST_INSERT_AFTER(listelm, elm, field) do { \
43 (elm)->field.next = (listelm)->field.next; \
44 (listelm)->field.next = (elm); \
47 #define AST_LIST_INSERT_HEAD(head, elm, field) do { \
48 (elm)->field.next = (head)->first; \
49 (head)->first = (elm); \
52 #define AST_LIST_INSERT_TAIL(head, elm, type, field) do { \
53 struct type *curelm = (head)->first; \
55 AST_LIST_INSERT_HEAD(head, elm, field); \
57 while ( curelm->field.next!=NULL ) { \
58 curelm=curelm->field.next; \
60 AST_LIST_INSERT_AFTER(curelm,elm,field); \
65 #define AST_LIST_REMOVE_HEAD(head, field) do { \
66 (head)->first = (head)->first->field.next; \
69 #define AST_LIST_REMOVE(head, elm, type, field) do { \
70 if ((head)->first == (elm)) { \
71 AST_LIST_REMOVE_HEAD((head), field); \
74 struct type *curelm = (head)->first; \
75 while( curelm->field.next != (elm) ) \
76 curelm = curelm->field.next; \
77 curelm->field.next = \
78 curelm->field.next->field.next; \