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

Generated on Fri Feb 27 12:19:42 2004 for Asterisk by doxygen 1.3.5