Fix little macro (bug #3100)
[asterisk/asterisk.git] / include / asterisk / linkedlists.h
index 30e09a0..75f0aa2 100755 (executable)
@@ -1,14 +1,13 @@
 #ifndef ASTERISK_LINKEDLISTS_H
 #define ASTERISK_LINKEDLISTS_H
 
-#include <pthread.h>
 #include <asterisk/lock.h>
 
 #define AST_LIST_LOCK(head)                                            \
-       ast_mutex_lock(&head->lock) 
+       ast_mutex_lock(&(head)->lock) 
        
 #define AST_LIST_UNLOCK(head)                                          \
-       ast_mutex_unlock(&head->lock)
+       ast_mutex_unlock(&(head)->lock)
 
 #define AST_LIST_HEAD(name, type)                                      \
 struct name {                                                          \
@@ -16,9 +15,6 @@ struct name {                                                         \
        ast_mutex_t lock;                                               \
 }
 
-#define AST_LIST_HEAD_INITIALIZER(head)                                        \
-       { NULL, AST_MUTEX_INITIALIZER }
-       
 #define AST_LIST_HEAD_SET(head,entry) do {                             \
        (head)->first=(entry);                                          \
        ast_pthread_mutex_init(&(head)->lock,NULL);                             \
@@ -55,10 +51,14 @@ struct {                                                            \
 
 #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)