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_SET(head,entry) do { \
00020
(head)->first=(entry); \
00021
ast_pthread_mutex_init(&(head)->lock,NULL); \
00022
} while (0)
00023
00024 #define AST_LIST_ENTRY(type) \
00025
struct { \
00026
struct type *next; \
00027
}
00028
00029 #define AST_LIST_FIRST(head) ((head)->first)
00030
00031 #define AST_LIST_NEXT(elm, field) ((elm)->field.next)
00032
00033 #define AST_LIST_EMPTY(head) (AST_LIST_FIRST(head) == NULL)
00034
00035 #define AST_LIST_TRAVERSE(head,var,field) \
00036
for((var) = (head)->first; (var); (var) = (var)->field.next)
00037
00038 #define AST_LIST_HEAD_INIT(head) { \
00039
(head)->first = NULL; \
00040
ast_pthread_mutex_init(&(head)->lock,NULL); \
00041
}
00042
00043 #define AST_LIST_INSERT_AFTER(listelm, elm, field) do { \
00044
(elm)->field.next = (listelm)->field.next; \
00045
(listelm)->field.next = (elm); \
00046
} while (0)
00047
00048 #define AST_LIST_INSERT_HEAD(head, elm, field) do { \
00049
(elm)->field.next = (head)->first; \
00050
(head)->first = (elm); \
00051
} while (0)
00052
00053 #define AST_LIST_INSERT_TAIL(head, elm, type, field) do { \
00054
struct type *curelm = (head)->first; \
00055
if(!curelm) { \
00056
AST_LIST_INSERT_HEAD(head, elm, field); \
00057
} else { \
00058
while ( curelm->field.next!=NULL ) { \
00059
curelm=curelm->field.next; \
00060
} \
00061
AST_LIST_INSERT_AFTER(curelm,elm,field); \
00062
} \
00063
} while (0)
00064
00065
00066 #define AST_LIST_REMOVE_HEAD(head, field) do { \
00067
(head)->first = (head)->first->field.next; \
00068
} while (0)
00069
00070 #define AST_LIST_REMOVE(head, elm, type, field) do { \
00071
if ((head)->first == (elm)) { \
00072
AST_LIST_REMOVE_HEAD((head), field); \
00073
} \
00074
else { \
00075
struct type *curelm = (head)->first; \
00076
while( curelm->field.next != (elm) ) \
00077
curelm = curelm->field.next; \
00078
curelm->field.next = \
00079
curelm->field.next->field.next; \
00080
} \
00081
} while (0)
00082
00083
#endif
Generated on Sat Jun 12 16:40:58 2004 for Asterisk by
1.3.7