diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-06-06 02:29:18 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-06-06 02:29:18 +0000 |
commit | 7b1b9f53ef47abd82c6faba12f4adcf721e622da (patch) | |
tree | be967c9ab3099202d13219196b5f17284a939e78 /res | |
parent | d39208dd35ce0ead92bf6a4b21361f3d13759589 (diff) |
more efficient (and understandable) ast_channel_walk_locked, and vastly more efficient ast_channel_by_name_locked (bug #4265)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5853 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rwxr-xr-x | res/res_agi.c | 38 | ||||
-rwxr-xr-x | res/res_features.c | 6 | ||||
-rwxr-xr-x | res/res_monitor.c | 27 | ||||
-rwxr-xr-x | res/res_musiconhold.c | 8 |
4 files changed, 22 insertions, 57 deletions
diff --git a/res/res_agi.c b/res/res_agi.c index da2889816..f1837b5f0 100755 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -960,19 +960,15 @@ static int handle_hangup(struct ast_channel *chan, AGI *agi, int argc, char **ar ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT); fdprintf(agi->fd, "200 result=1\n"); return RESULT_SUCCESS; - } else if (argc == 2) { + } else if (argc == 2) { /* one argument: look for info on the specified channel */ - c = ast_channel_walk_locked(NULL); - while (c) { - if (strcasecmp(argv[1], c->name) == 0) { - /* we have a matching channel */ - ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT); - fdprintf(agi->fd, "200 result=1\n"); - ast_mutex_unlock(&c->lock); - return RESULT_SUCCESS; - } + c = ast_get_channel_by_name_locked(argv[1]); + if (c) { + /* we have a matching channel */ + ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT); + fdprintf(agi->fd, "200 result=1\n"); ast_mutex_unlock(&c->lock); - c = ast_channel_walk_locked(c); + return RESULT_SUCCESS; } /* if we get this far no channel name matched the argument given */ fdprintf(agi->fd, "200 result=-1\n"); @@ -1036,15 +1032,11 @@ static int handle_channelstatus(struct ast_channel *chan, AGI *agi, int argc, ch return RESULT_SUCCESS; } else if (argc == 3) { /* one argument: look for info on the specified channel */ - c = ast_channel_walk_locked(NULL); - while (c) { - if (strcasecmp(argv[2],c->name)==0) { - fdprintf(agi->fd, "200 result=%d\n", c->_state); - ast_mutex_unlock(&c->lock); - return RESULT_SUCCESS; - } + c = ast_get_channel_by_name_locked(argv[2]); + if (c) { + fdprintf(agi->fd, "200 result=%d\n", c->_state); ast_mutex_unlock(&c->lock); - c = ast_channel_walk_locked(c); + return RESULT_SUCCESS; } /* if we get this far no channel name matched the argument given */ fdprintf(agi->fd, "200 result=-1\n"); @@ -1087,15 +1079,11 @@ static int handle_getvariablefull(struct ast_channel *chan, AGI *agi, int argc, if ((argc != 4) && (argc != 5)) return RESULT_SHOWUSAGE; if (argc == 5) { - while((chan2 = ast_channel_walk_locked(chan2))) { - if (!strcmp(chan2->name, argv[4])) - break; - ast_mutex_unlock(&chan2->lock); - } + chan2 = ast_get_channel_by_name_locked(argv[4]); } else { chan2 = chan; } - if (chan) { + if (chan) { /* XXX isn't this chan2 ? */ pbx_substitute_variables_helper(chan2, argv[3], tmp, sizeof(tmp) - 1); fdprintf(agi->fd, "200 result=1 (%s)\n", tmp); } else { diff --git a/res/res_features.c b/res/res_features.c index d6363e112..15546c040 100755 --- a/res/res_features.c +++ b/res/res_features.c @@ -1661,10 +1661,9 @@ int load_module(void) int ast_pickup_call(struct ast_channel *chan) { - struct ast_channel *cur; + struct ast_channel *cur = NULL; int res = -1; - cur = ast_channel_walk_locked(NULL); - while(cur) { + while ( (cur = ast_channel_walk_locked(cur)) != NULL) { if (!cur->pbx && (cur != chan) && (chan->pickupgroup & cur->callgroup) && @@ -1673,7 +1672,6 @@ int ast_pickup_call(struct ast_channel *chan) break; } ast_mutex_unlock(&cur->lock); - cur = ast_channel_walk_locked(cur); } if (cur) { if (option_debug) diff --git a/res/res_monitor.c b/res/res_monitor.c index cff024dc9..62d35dd1d 100755 --- a/res/res_monitor.c +++ b/res/res_monitor.c @@ -413,14 +413,7 @@ static int start_monitor_action(struct mansession *s, struct message *m) astman_send_error(s, m, "No channel specified"); return 0; } - c = ast_channel_walk_locked(NULL); - while (c) { - if (!strcasecmp(c->name, name)) { - break; - } - ast_mutex_unlock(&c->lock); - c = ast_channel_walk_locked(c); - } + c = ast_get_channel_by_name_locked(name); if (!c) { astman_send_error(s, m, "No such channel"); return 0; @@ -471,14 +464,7 @@ static int stop_monitor_action(struct mansession *s, struct message *m) astman_send_error(s, m, "No channel specified"); return 0; } - c = ast_channel_walk_locked(NULL); - while(c) { - if (!strcasecmp(c->name, name)) { - break; - } - ast_mutex_unlock(&c->lock); - c = ast_channel_walk_locked(c); - } + c = ast_get_channel_by_name_locked(name); if (!c) { astman_send_error(s, m, "No such channel"); return 0; @@ -514,14 +500,7 @@ static int change_monitor_action(struct mansession *s, struct message *m) astman_send_error(s, m, "No filename specified"); return 0; } - c = ast_channel_walk_locked(NULL); - while(c) { - if (!strcasecmp(c->name, name)) { - break; - } - ast_mutex_unlock(&c->lock); - c = ast_channel_walk_locked(c); - } + c = ast_get_channel_by_name_locked(name); if (!c) { astman_send_error(s, m, "No such channel"); return 0; diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index df018b429..3b8c5b098 100755 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -962,10 +962,11 @@ static void ast_moh_destroy(void) ast_mutex_unlock(&moh_lock); } -static void moh_on_off(int on) { - struct ast_channel *chan = ast_channel_walk_locked(NULL); +static void moh_on_off(int on) +{ + struct ast_channel *chan = NULL; - while (chan) { + while ( (chan = ast_channel_walk_locked(chan)) != NULL) { if (ast_test_flag(chan, AST_FLAG_MOH)) { if (on) local_ast_moh_start(chan, NULL); @@ -973,7 +974,6 @@ static void moh_on_off(int on) { ast_deactivate_generator(chan); } ast_mutex_unlock(&chan->lock); - chan = ast_channel_walk_locked(chan); } } |