diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-05-20 16:30:10 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-05-20 16:30:10 +0000 |
commit | ec76498f552e4ff10adcaa0ffc27d1c21cb5792e (patch) | |
tree | efbb775d4f7e80cb61b314075217774d082e881a /apps | |
parent | 7e42c962d89de0673789eed30649fc7ae276aa50 (diff) |
Make ast_channel_walk become ast_channel_walk_locked
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3029 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rwxr-xr-x | apps/app_agi.c | 16 | ||||
-rwxr-xr-x | apps/app_groupcount.c | 9 | ||||
-rwxr-xr-x | apps/app_setcdruserfield.c | 6 | ||||
-rwxr-xr-x | apps/app_softhangup.c | 6 | ||||
-rwxr-xr-x | apps/app_zapscan.c | 76 |
5 files changed, 60 insertions, 53 deletions
diff --git a/apps/app_agi.c b/apps/app_agi.c index ba479b28e..d7af708b4 100755 --- a/apps/app_agi.c +++ b/apps/app_agi.c @@ -692,15 +692,17 @@ static int handle_hangup(struct ast_channel *chan, AGI *agi, int argc, char **ar return RESULT_SUCCESS; } else if (argc==2) { /* one argument: look for info on the specified channel */ - c = ast_channel_walk(NULL); + 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_softhangup(c,AST_SOFTHANGUP_EXPLICIT); + fdprintf(agi->fd, "200 result=1\n"); + ast_mutex_unlock(&c->lock); return RESULT_SUCCESS; } - c = ast_channel_walk(c); + ast_mutex_unlock(&c->lock); + c = ast_channel_walk_locked(c); } /* if we get this far no channel name matched the argument given */ fdprintf(agi->fd, "200 result=-1\n"); @@ -753,13 +755,15 @@ 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(NULL); + 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_channel_walk(c); + ast_mutex_unlock(&c->lock); + c = ast_channel_walk_locked(c); } /* if we get this far no channel name matched the argument given */ fdprintf(agi->fd, "200 result=-1\n"); diff --git a/apps/app_groupcount.c b/apps/app_groupcount.c index ef7b92cd9..b97a77466 100755 --- a/apps/app_groupcount.c +++ b/apps/app_groupcount.c @@ -58,20 +58,17 @@ LOCAL_USER_DECL; static int group_get_count(char *group) { - /* XXX ast_channel_walk needs to be modified to - prevent a race in which after we return the channel - is no longer valid (or ast_channel_free can be modified - just as well) XXX */ struct ast_channel *chan; int count = 0; char *test; if (group && !ast_strlen_zero(group)) { - chan = ast_channel_walk(NULL); + chan = ast_channel_walk_locked(NULL); while(chan) { test = pbx_builtin_getvar_helper(chan, "GROUP"); if (test && !strcasecmp(test, group)) count++; - chan = ast_channel_walk(chan); + ast_mutex_unlock(&chan->lock); + chan = ast_channel_walk_locked(chan); } } return count; diff --git a/apps/app_setcdruserfield.c b/apps/app_setcdruserfield.c index bb1bb339e..d0ebd2e13 100755 --- a/apps/app_setcdruserfield.c +++ b/apps/app_setcdruserfield.c @@ -76,11 +76,12 @@ static int action_setcdruserfield(struct mansession *s, struct message *m) astman_send_error(s, m, "No UserField specified"); return 0; } - c = ast_channel_walk(NULL); + c = ast_channel_walk_locked(NULL); while (c) { if (!strcasecmp(c->name, channel)) break; - c = ast_channel_walk(c); + ast_mutex_unlock(&c->lock); + c = ast_channel_walk_locked(c); } if (!c) { astman_send_error(s, m, "No such channel"); @@ -90,6 +91,7 @@ static int action_setcdruserfield(struct mansession *s, struct message *m) ast_cdr_appenduserfield(c, userfield); else ast_cdr_setuserfield(c, userfield); + ast_mutex_unlock(&c->lock); astman_send_ack(s, m, "CDR Userfield Set"); return 0; } diff --git a/apps/app_softhangup.c b/apps/app_softhangup.c index 497f03860..43a42247c 100755 --- a/apps/app_softhangup.c +++ b/apps/app_softhangup.c @@ -47,13 +47,15 @@ static int softhangup_exec(struct ast_channel *chan, void *data) return 0; } LOCAL_USER_ADD(u); - c = ast_channel_walk(NULL); + c = ast_channel_walk_locked(NULL); while (c) { if (!strcasecmp(c->name, data)) { ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT); + ast_mutex_unlock(&c->lock); break; } - c = ast_channel_walk(c); + ast_mutex_unlock(&c->lock); + c = ast_channel_walk_locked(c); } LOCAL_USER_REMOVE(u); diff --git a/apps/app_zapscan.c b/apps/app_zapscan.c index ab87f592c..58a456f38 100755 --- a/apps/app_zapscan.c +++ b/apps/app_zapscan.c @@ -54,17 +54,18 @@ LOCAL_USER_DECL; #define CONF_SIZE 160 -static struct ast_channel *get_zap_channel(int num) { +static struct ast_channel *get_zap_channel_locked(int num) { struct ast_channel *c=NULL; char name[80]; snprintf(name,sizeof(name),"Zap/%d-1",num); - c = ast_channel_walk(NULL); + c = ast_channel_walk_locked(NULL); while(c) { if (!strcasecmp(c->name, name)) { break; } - c = ast_channel_walk(c); + ast_mutex_unlock(&c->lock); + c = ast_channel_walk_locked(c); } if (c) return c; @@ -293,43 +294,44 @@ static int conf_exec(struct ast_channel *chan, void *data) ast_answer(chan); for (;;) { - if (ast_waitfor(chan, 100) < 0) - break; - f = ast_read(chan); - if (!f) - break; - if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '*')) { + if (ast_waitfor(chan, 100) < 0) + break; + + f = ast_read(chan); + if (!f) + break; + if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '*')) { + ast_frfree(f); + break; + } ast_frfree(f); - break; - } - ast_frfree(f); - ichan = NULL; - if(input) { - ichan = get_zap_channel(input); - input = 0; - } - - tempchan = ichan ? ichan : ast_channel_walk(tempchan); - - - if ( !tempchan && !lastchan ) - break; - if ( tempchan && tempchan->type && (!strcmp(tempchan->type, "Zap")) && (tempchan != chan) ) { - ast_verbose(VERBOSE_PREFIX_3 "Zap channel %s is in-use, monitoring...\n", tempchan->name); - strcpy(confstr, tempchan->name); - if ((tmp = strchr(confstr,'-'))) { - *tmp = '\0'; + ichan = NULL; + if(input) { + ichan = get_zap_channel_locked(input); + input = 0; } - confno = atoi(strchr(confstr,'/') + 1); - ast_stopstream(chan); - ast_say_number(chan, confno, AST_DIGIT_ANY, chan->language, (char *) NULL); - res = conf_run(chan, confno, confflags); - if (res<0) break; - input = res; - } - lastchan = tempchan; + + tempchan = ichan ? ichan : ast_channel_walk_locked(tempchan); + + + if ( !tempchan && !lastchan ) + break; + if ( tempchan && tempchan->type && (!strcmp(tempchan->type, "Zap")) && (tempchan != chan) ) { + ast_verbose(VERBOSE_PREFIX_3 "Zap channel %s is in-use, monitoring...\n", tempchan->name); + strcpy(confstr, tempchan->name); + ast_mutex_unlock(&tempchan->lock); + if ((tmp = strchr(confstr,'-'))) { + *tmp = '\0'; + } + confno = atoi(strchr(confstr,'/') + 1); + ast_stopstream(chan); + ast_say_number(chan, confno, AST_DIGIT_ANY, chan->language, (char *) NULL); + res = conf_run(chan, confno, confflags); + if (res<0) break; + input = res; + } + lastchan = tempchan; } - LOCAL_USER_REMOVE(u); return res; } |