#ifndef ASTERISK_LINKEDLISTS_H
#define ASTERISK_LINKEDLISTS_H
-#include <pthread.h>
+#include <asterisk/lock.h>
#define AST_LIST_LOCK(head) \
- ast_pthread_mutex_lock(&head->lock)
+ ast_mutex_lock(&(head)->lock)
#define AST_LIST_UNLOCK(head) \
- ast_pthread_mutex_unlock(&head->lock)
+ ast_mutex_unlock(&(head)->lock)
#define AST_LIST_HEAD(name, type) \
struct name { \
struct type *first; \
- pthread_mutex_t lock; \
+ ast_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); \
+ ast_pthread_mutex_init(&(head)->lock,NULL); \
} while (0)
#define AST_LIST_ENTRY(type) \
#define AST_LIST_HEAD_INIT(head) { \
(head)->first = NULL; \
- pthread_mutex_init(&(head)->lock,NULL); \
+ ast_pthread_mutex_init(&(head)->lock,NULL); \
}
#define AST_LIST_INSERT_AFTER(listelm, elm, field) do { \
#define AST_LIST_INSERT_TAIL(head, elm, type, field) do { \
struct type *curelm = (head)->first; \
- while ( curelm->field.next!=NULL ) { \
- curelm=curelm->field.next; \
+ if(!curelm) { \
+ AST_LIST_INSERT_HEAD(head, elm, field); \
+ } else { \
+ while ( curelm->field.next!=NULL ) { \
+ curelm=curelm->field.next; \
+ } \
+ AST_LIST_INSERT_AFTER(curelm,elm,field); \
} \
- AST_LIST_INSERT_AFTER(curelm,elm,field); \
} while (0)