aboutsummaryrefslogtreecommitdiffstats
path: root/main/pbx.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-04-24 14:04:26 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-04-24 14:04:26 +0000
commit89175b7e049f8203ece12ba74301d7ad9385c050 (patch)
tree1812569845aaf29df5f2a18285e73bc1fcc6268c /main/pbx.c
parenta8182a597e392aa831f2e6960a71d3554fc34aa9 (diff)
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big improvement for performance, stability, code maintainability, and ease of future code development. The channel list is no longer an unsorted linked list. The main container for channels is an astobj2 hash table. All of the code related to searching for channels or iterating active channels has been rewritten. Let n be the number of active channels. Iterating the channel list has gone from O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1). Searching for a channel by extension is still O(n), but uses a new method for doing so, which is more efficient. The ast_channel object is now a reference counted object. The benefits here are plentiful. Some benefits directly related to issues in the previous code include: 1) When threads other than the channel thread owning a channel wanted access to a channel, it had to hold the lock on it to ensure that it didn't go away. This is no longer a requirement. Holding a reference is sufficient. 2) There are places that now require less dealing with channel locks. 3) There are places where channel locks are held for much shorter periods of time. 4) There are places where dealing with more than one channel at a time becomes _MUCH_ easier. ChanSpy is a great example of this. Writing code in the future that deals with multiple channels will be much easier. Some additional information regarding channel locking and reference count handling can be found in channel.h, where a new section has been added that discusses some of the rules associated with it. Mark Michelson also assisted with the development of this patch. He did the conversion of ChanSpy and introduced a new API, ast_autochan, which makes it much easier to deal with holding on to a channel pointer for an extended period of time and having it get automatically updated if the channel gets masqueraded. Mark was also a huge help in the code review process. Thanks to David Vossel for his assistance with this branch, as well. David did the conversion of the DAHDIScan application by making it become a wrapper for ChanSpy internally. The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch. Review: http://reviewboard.digium.com/r/203/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/pbx.c')
-rw-r--r--main/pbx.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/main/pbx.c b/main/pbx.c
index 0c7105a09..1aad50dfb 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -3488,7 +3488,7 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
cp4 = ast_func_read(bogus, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
/* Don't deallocate the varshead that was passed in */
memcpy(&bogus->varshead, &old, sizeof(bogus->varshead));
- ast_channel_free(bogus);
+ bogus = ast_channel_release(bogus);
} else
ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n");
}
@@ -6134,16 +6134,19 @@ static char *handle_show_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cl
if (a->argc != e->args + 1)
return CLI_SHOWUSAGE;
- if (!(chan = ast_get_channel_by_name_locked(a->argv[e->args]))) {
+ if (!(chan = ast_channel_get_by_name(a->argv[e->args]))) {
ast_cli(a->fd, "Channel '%s' not found\n", a->argv[e->args]);
return CLI_FAILURE;
}
pbx_builtin_serialize_variables(chan, &vars);
+
if (ast_str_strlen(vars)) {
ast_cli(a->fd, "\nVariables for channel %s:\n%s\n", a->argv[e->args], ast_str_buffer(vars));
}
- ast_channel_unlock(chan);
+
+ chan = ast_channel_unref(chan);
+
return CLI_SUCCESS;
}
@@ -6192,13 +6195,15 @@ static char *handle_set_chanvar(struct ast_cli_entry *e, int cmd, struct ast_cli
var_name = a->argv[e->args + 1];
var_value = a->argv[e->args + 2];
- if (!(chan = ast_get_channel_by_name_locked(chan_name))) {
+ if (!(chan = ast_channel_get_by_name(chan_name))) {
ast_cli(a->fd, "Channel '%s' not found\n", chan_name);
return CLI_FAILURE;
}
pbx_builtin_setvar_helper(chan, var_name, var_value);
- ast_channel_unlock(chan);
+
+ chan = ast_channel_unref(chan);
+
ast_cli(a->fd, "\n -- Channel variable '%s' set to '%s' for '%s'\n", var_name, var_value, chan_name);
return CLI_SUCCESS;
@@ -7303,11 +7308,11 @@ int ast_async_goto_by_name(const char *channame, const char *context, const char
struct ast_channel *chan;
int res = -1;
- chan = ast_get_channel_by_name_locked(channame);
- if (chan) {
+ if ((chan = ast_channel_get_by_name(channame))) {
res = ast_async_goto(chan, context, exten, priority);
- ast_channel_unlock(chan);
+ chan = ast_channel_unref(chan);
}
+
return res;
}
@@ -7823,7 +7828,7 @@ static int ast_pbx_outgoing_cdr_failed(void)
if (!chan->cdr) {
/* allocation of the cdr failed */
- ast_channel_free(chan); /* free the channel */
+ chan = ast_channel_release(chan); /* free the channel */
return -1; /* return failure */
}
@@ -7834,7 +7839,7 @@ static int ast_pbx_outgoing_cdr_failed(void)
ast_cdr_failed(chan->cdr); /* set the status to failed */
ast_cdr_detach(chan->cdr); /* post and free the record */
chan->cdr = NULL;
- ast_channel_free(chan); /* free the channel */
+ chan = ast_channel_release(chan); /* free the channel */
return 0; /* success */
}
@@ -9030,14 +9035,14 @@ int pbx_builtin_importvar(struct ast_channel *chan, void *data)
name = strsep(&value,"=");
channel = strsep(&value,",");
if (channel && value && name) { /*! \todo XXX should do !ast_strlen_zero(..) of the args ? */
- struct ast_channel *chan2 = ast_get_channel_by_name_locked(channel);
+ struct ast_channel *chan2 = ast_channel_get_by_name(channel);
if (chan2) {
char *s = alloca(strlen(value) + 4);
if (s) {
sprintf(s, "${%s}", value);
pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1);
}
- ast_channel_unlock(chan2);
+ chan2 = ast_channel_unref(chan2);
}
pbx_builtin_setvar_helper(chan, name, tmp);
}