Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

linkedlists.h

Go to the documentation of this file.
00001 #ifndef ASTERISK_LINKEDLISTS_H
00002 #define ASTERISK_LINKEDLISTS_H
00003 
00004 #include <asterisk/lock.h>
00005 
00006 #define AST_LIST_LOCK(head)                  \
00007    ast_mutex_lock(&head->lock) 
00008    
00009 #define AST_LIST_UNLOCK(head)                   \
00010    ast_mutex_unlock(&head->lock)
00011 
00012 #define AST_LIST_HEAD(name, type)               \
00013 struct name {                       \
00014    struct type *first;                 \
00015    ast_mutex_t lock;                \
00016 }
00017 
00018 #define AST_LIST_HEAD_SET(head,entry) do {            \
00019    (head)->first=(entry);                 \
00020    ast_pthread_mutex_init(&(head)->lock,NULL);           \
00021 } while (0)
00022 
00023 #define AST_LIST_ENTRY(type)                 \
00024 struct {                      \
00025    struct type *next;                  \
00026 }
00027  
00028 #define  AST_LIST_FIRST(head) ((head)->first)
00029 
00030 #define AST_LIST_NEXT(elm, field)   ((elm)->field.next)
00031 
00032 #define  AST_LIST_EMPTY(head) (AST_LIST_FIRST(head) == NULL)
00033 
00034 #define AST_LIST_TRAVERSE(head,var,field)             \
00035    for((var) = (head)->first; (var); (var) = (var)->field.next)
00036 
00037 #define AST_LIST_HEAD_INIT(head) {                 \
00038    (head)->first = NULL;                  \
00039    ast_pthread_mutex_init(&(head)->lock,NULL);           \
00040 }
00041 
00042 #define AST_LIST_INSERT_AFTER(listelm, elm, field) do {     \
00043    (elm)->field.next = (listelm)->field.next;         \
00044    (listelm)->field.next = (elm);            \
00045 } while (0)
00046 
00047 #define AST_LIST_INSERT_HEAD(head, elm, field) do {         \
00048       (elm)->field.next = (head)->first;        \
00049       (head)->first = (elm);              \
00050 } while (0)
00051 
00052 #define AST_LIST_INSERT_TAIL(head, elm, type, field) do {             \
00053       struct type *curelm = (head)->first;                            \
00054       if(!curelm) {                                                   \
00055               AST_LIST_INSERT_HEAD(head, elm, field);                 \
00056       } else {                                                        \
00057               while ( curelm->field.next!=NULL ) {                    \
00058                       curelm=curelm->field.next;                      \
00059               }                                                       \
00060               AST_LIST_INSERT_AFTER(curelm,elm,field);                \
00061       }                                                               \
00062 } while (0)
00063 
00064 
00065 #define AST_LIST_REMOVE_HEAD(head, field) do {              \
00066       (head)->first = (head)->first->field.next;         \
00067    } while (0)
00068 
00069 #define AST_LIST_REMOVE(head, elm, type, field) do {        \
00070    if ((head)->first == (elm)) {             \
00071       AST_LIST_REMOVE_HEAD((head), field);         \
00072    }                       \
00073    else {                        \
00074       struct type *curelm = (head)->first;         \
00075       while( curelm->field.next != (elm) )         \
00076          curelm = curelm->field.next;        \
00077       curelm->field.next =             \
00078           curelm->field.next->field.next;       \
00079    }                       \
00080 } while (0)
00081 
00082 #endif

Generated on Sat Nov 25 19:09:38 2006 for Asterisk by  doxygen 1.4.2