aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/linkedlists.h
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2002-09-06 15:22:51 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2002-09-06 15:22:51 +0000
commitd08711bdf946cc47e54f36c0039ebdd578007249 (patch)
tree54def398984ce83b00cd8e5e89f149c905fd4808 /include/asterisk/linkedlists.h
parentbfc8985acdef79d49fb2992b6525324b79897c64 (diff)
Version 0.2.0 from FTP
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@519 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/linkedlists.h')
-rwxr-xr-xinclude/asterisk/linkedlists.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/include/asterisk/linkedlists.h b/include/asterisk/linkedlists.h
new file mode 100755
index 000000000..c1a3d9de3
--- /dev/null
+++ b/include/asterisk/linkedlists.h
@@ -0,0 +1,81 @@
+#ifndef ASTERISK_LINKEDLISTS_H
+#define ASTERISK_LINKEDLISTS_H
+
+#include <pthread.h>
+
+#define AST_LIST_LOCK(head) \
+ ast_pthread_mutex_lock(&head->lock)
+
+#define AST_LIST_UNLOCK(head) \
+ ast_pthread_mutex_unlock(&head->lock)
+
+#define AST_LIST_HEAD(name, type) \
+struct name { \
+ struct type *first; \
+ pthread_mutex_t lock; \
+}
+
+#define AST_LIST_HEAD_INITIALIZER(head) \
+ { NULL, PTHREAD_MUTEX_INITIALIZER }
+
+#define AST_LIST_HEAD_SET(head,entry) do { \
+ (head)->first=(entry); \
+ pthread_mutex_init(&(head)->lock,NULL); \
+} while (0)
+
+#define AST_LIST_ENTRY(type) \
+struct { \
+ struct type *next; \
+}
+
+#define AST_LIST_FIRST(head) ((head)->first)
+
+#define AST_LIST_NEXT(elm, field) ((elm)->field.next)
+
+#define AST_LIST_EMPTY(head) (AST_LIST_FIRST(head) == NULL)
+
+#define AST_LIST_TRAVERSE(head,var,field) \
+ for((var) = (head)->first; (var); (var) = (var)->field.next)
+
+#define AST_LIST_HEAD_INIT(head) { \
+ (head)->first = NULL; \
+ pthread_mutex_init(&(head)->lock,NULL); \
+}
+
+#define AST_LIST_INSERT_AFTER(listelm, elm, field) do { \
+ (elm)->field.next = (listelm)->field.next; \
+ (listelm)->field.next = (elm); \
+} while (0)
+
+#define AST_LIST_INSERT_HEAD(head, elm, field) do { \
+ (elm)->field.next = (head)->first; \
+ (head)->first = (elm); \
+} while (0)
+
+#define AST_LIST_INSERT_TAIL(head, elm, type, field) do { \
+ struct type *curelm = (head)->first; \
+ while ( curelm->field.next!=NULL ) { \
+ curelm=curelm->field.next; \
+ } \
+ AST_LIST_INSERT_AFTER(curelm,elm,field); \
+} while (0)
+
+
+#define AST_LIST_REMOVE_HEAD(head, field) do { \
+ (head)->first = (head)->first->field.next; \
+ } while (0)
+
+#define AST_LIST_REMOVE(head, elm, type, field) do { \
+ if ((head)->first == (elm)) { \
+ AST_LIST_REMOVE_HEAD((head), field); \
+ } \
+ else { \
+ struct type *curelm = (head)->first; \
+ while( curelm->field.next != (elm) ) \
+ curelm = curelm->field.next; \
+ curelm->field.next = \
+ curelm->field.next->field.next; \
+ } \
+} while (0)
+
+#endif