fix various bugs related to list handling of channel variables (issue #5548)
authorKevin P. Fleming <kpfleming@digium.com>
Mon, 31 Oct 2005 15:34:11 +0000 (15:34 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Mon, 31 Oct 2005 15:34:11 +0000 (15:34 +0000)
use nolock lists for channel variables, since no locks are needed (these lists are either temporary or protected by the channel's own lock)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6900 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channel.c
include/asterisk/cdr.h
include/asterisk/chanvars.h
include/asterisk/linkedlists.h
pbx.c
pbx/pbx_dundi.c
pbx/pbx_loopback.c

index c3f3d03..6aa64e4 100755 (executable)
--- a/channel.c
+++ b/channel.c
@@ -585,7 +585,7 @@ struct ast_channel *ast_channel_alloc(int needqueue)
        snprintf(tmp->uniqueid, sizeof(tmp->uniqueid), "%li.%d", (long) time(NULL), uniqueint++);
        headp = &tmp->varshead;
        ast_mutex_init(&tmp->lock);
        snprintf(tmp->uniqueid, sizeof(tmp->uniqueid), "%li.%d", (long) time(NULL), uniqueint++);
        headp = &tmp->varshead;
        ast_mutex_init(&tmp->lock);
-       AST_LIST_HEAD_INIT(headp);
+       AST_LIST_HEAD_INIT_NOLOCK(headp);
        strcpy(tmp->context, "default");
        ast_copy_string(tmp->language, defaultlanguage, sizeof(tmp->language));
        strcpy(tmp->exten, "s");
        strcpy(tmp->context, "default");
        ast_copy_string(tmp->language, defaultlanguage, sizeof(tmp->language));
        strcpy(tmp->exten, "s");
@@ -2976,7 +2976,7 @@ int ast_do_masquerade(struct ast_channel *original)
                original->fds[x] = clone->fds[x];
        }
        clone_variables(original, clone);
                original->fds[x] = clone->fds[x];
        }
        clone_variables(original, clone);
-       clone->varshead.first = NULL;
+       AST_LIST_HEAD_INIT_NOLOCK(&clone->varshead);
        /* Presense of ADSI capable CPE follows clone */
        original->adsicpe = clone->adsicpe;
        /* Bridge remains the same */
        /* Presense of ADSI capable CPE follows clone */
        original->adsicpe = clone->adsicpe;
        /* Bridge remains the same */
index e14b7c6..2ca5671 100755 (executable)
@@ -47,7 +47,6 @@
 #include "asterisk/channel.h"
 
 struct ast_channel;
 #include "asterisk/channel.h"
 
 struct ast_channel;
-AST_LIST_HEAD(varshead,ast_var_t);
 
 /*! Responsible for call detail data */
 struct ast_cdr {
 
 /*! Responsible for call detail data */
 struct ast_cdr {
index 32cccf3..d31c05e 100755 (executable)
@@ -31,6 +31,8 @@ struct ast_var_t {
        char name[0];
 };
 
        char name[0];
 };
 
+AST_LIST_HEAD_NOLOCK(varshead, ast_var_t);
+
 struct ast_var_t *ast_var_assign(const char *name, const char *value);
 void ast_var_delete(struct ast_var_t *var);
 char *ast_var_name(struct ast_var_t *var);
 struct ast_var_t *ast_var_assign(const char *name, const char *value);
 void ast_var_delete(struct ast_var_t *var);
 char *ast_var_name(struct ast_var_t *var);
index 3dcd9a5..fd2203c 100755 (executable)
@@ -369,6 +369,8 @@ struct {                                                            \
 #define AST_LIST_INSERT_HEAD(head, elm, field) do {                    \
                (elm)->field.next = (head)->first;                      \
                (head)->first = (elm);                                  \
 #define AST_LIST_INSERT_HEAD(head, elm, field) do {                    \
                (elm)->field.next = (head)->first;                      \
                (head)->first = (elm);                                  \
+               if (!(head)->last)                                      \
+                       (head)->last = (elm);                           \
 } while (0)
 
 /*!
 } while (0)
 
 /*!
diff --git a/pbx.c b/pbx.c
index 98250d1..c545988 100755 (executable)
--- a/pbx.c
+++ b/pbx.c
@@ -6150,7 +6150,7 @@ int load_pbx(void)
                ast_verbose( "Asterisk PBX Core Initializing\n");
                ast_verbose( "Registering builtin applications:\n");
        }
                ast_verbose( "Asterisk PBX Core Initializing\n");
                ast_verbose( "Registering builtin applications:\n");
        }
-       AST_LIST_HEAD_INIT(&globals);
+       AST_LIST_HEAD_INIT_NOLOCK(&globals);
        ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(pbx_cli[0]));
 
        /* Register builtin applications */
        ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(pbx_cli[0]));
 
        /* Register builtin applications */
index 0dce967..c0165d9 100755 (executable)
@@ -559,7 +559,7 @@ static int dundi_lookup_local(struct dundi_result *dr, struct dundi_mapping *map
                        dr[anscnt].eid = *us_eid;
                        dundi_eid_to_str(dr[anscnt].eid_str, sizeof(dr[anscnt].eid_str), &dr[anscnt].eid);
                        if (ast_test_flag(&flags, DUNDI_FLAG_EXISTS)) {
                        dr[anscnt].eid = *us_eid;
                        dundi_eid_to_str(dr[anscnt].eid_str, sizeof(dr[anscnt].eid_str), &dr[anscnt].eid);
                        if (ast_test_flag(&flags, DUNDI_FLAG_EXISTS)) {
-                               AST_LIST_HEAD_INIT(&headp);
+                               AST_LIST_HEAD_INIT_NOLOCK(&headp);
                                newvariable = ast_var_assign("NUMBER", called_number);
                                AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
                                newvariable = ast_var_assign("EID", dr[anscnt].eid_str);
                                newvariable = ast_var_assign("NUMBER", called_number);
                                AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
                                newvariable = ast_var_assign("EID", dr[anscnt].eid_str);
index aeba07d..6fa35f2 100755 (executable)
@@ -88,7 +88,7 @@ static char *loopback_helper(char *buf, int buflen, const char *exten, const cha
 
        snprintf(tmp, sizeof(tmp), "%d", priority);
        memset(buf, 0, buflen);
 
        snprintf(tmp, sizeof(tmp), "%d", priority);
        memset(buf, 0, buflen);
-       AST_LIST_HEAD_INIT(&headp);
+       AST_LIST_HEAD_INIT_NOLOCK(&headp);
        newvariable = ast_var_assign("EXTEN", exten);
        AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
        newvariable = ast_var_assign("CONTEXT", context);
        newvariable = ast_var_assign("EXTEN", exten);
        AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
        newvariable = ast_var_assign("CONTEXT", context);