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       while ( curelm->field.next!=NULL ) {                            \
00059               curelm=curelm->field.next;                              \
00060       }                                                               \
00061       AST_LIST_INSERT_AFTER(curelm,elm,field);                        \
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 Fri Oct 31 07:05:06 2003 for Asterisk by doxygen 1.3.4