1 #ifndef ASTERISK_LINKEDLISTS_H
2 #define ASTERISK_LINKEDLISTS_H
5 #include <asterisk/lock.h>
7 #define AST_LIST_LOCK(head) \
8 ast_mutex_lock(&head->lock)
10 #define AST_LIST_UNLOCK(head) \
11 ast_mutex_unlock(&head->lock)
13 #define AST_LIST_HEAD(name, type) \
19 #define AST_LIST_HEAD_INITIALIZER(head) \
20 { NULL, AST_MUTEX_INITIALIZER }
22 #define AST_LIST_HEAD_SET(head,entry) do { \
23 (head)->first=(entry); \
24 ast_pthread_mutex_init(&(head)->lock,NULL); \
27 #define AST_LIST_ENTRY(type) \
32 #define AST_LIST_FIRST(head) ((head)->first)
34 #define AST_LIST_NEXT(elm, field) ((elm)->field.next)
36 #define AST_LIST_EMPTY(head) (AST_LIST_FIRST(head) == NULL)
38 #define AST_LIST_TRAVERSE(head,var,field) \
39 for((var) = (head)->first; (var); (var) = (var)->field.next)
41 #define AST_LIST_HEAD_INIT(head) { \
42 (head)->first = NULL; \
43 ast_pthread_mutex_init(&(head)->lock,NULL); \
46 #define AST_LIST_INSERT_AFTER(listelm, elm, field) do { \
47 (elm)->field.next = (listelm)->field.next; \
48 (listelm)->field.next = (elm); \
51 #define AST_LIST_INSERT_HEAD(head, elm, field) do { \
52 (elm)->field.next = (head)->first; \
53 (head)->first = (elm); \
56 #define AST_LIST_INSERT_TAIL(head, elm, type, field) do { \
57 struct type *curelm = (head)->first; \
59 AST_LIST_INSERT_HEAD(head, elm, field); \
61 while ( curelm->field.next!=NULL ) { \
62 curelm=curelm->field.next; \
64 AST_LIST_INSERT_AFTER(curelm,elm,field); \
69 #define AST_LIST_REMOVE_HEAD(head, field) do { \
70 (head)->first = (head)->first->field.next; \
73 #define AST_LIST_REMOVE(head, elm, type, field) do { \
74 if ((head)->first == (elm)) { \
75 AST_LIST_REMOVE_HEAD((head), field); \
78 struct type *curelm = (head)->first; \
79 while( curelm->field.next != (elm) ) \
80 curelm = curelm->field.next; \
81 curelm->field.next = \
82 curelm->field.next->field.next; \