Make ast_channel_walk become ast_channel_walk_locked

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3029 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2004-05-20 16:30:10 +00:00
parent e1b72cf020
commit 6195dd35e0
13 changed files with 153 additions and 95 deletions

View File

@@ -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");

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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 == '*')) {
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';
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;
}
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;
ast_frfree(f);
ichan = NULL;
if(input) {
ichan = get_zap_channel_locked(input);
input = 0;
}
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;
}