[Asterisk-cvs] asterisk/apps app_agi.c,1.39,1.40 app_groupcount.c,1.3,1.4 app_setcdruserfield.c,1.4,1.5 app_softhangup.c,1.2,1.3 app_zapscan.c,1.9,1.10

markster at lists.digium.com markster at lists.digium.com
Thu May 20 12:17:25 CDT 2004


Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv6480/apps

Modified Files:
	app_agi.c app_groupcount.c app_setcdruserfield.c 
	app_softhangup.c app_zapscan.c 
Log Message:
Make ast_channel_walk become ast_channel_walk_locked


Index: app_agi.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_agi.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- app_agi.c	15 May 2004 15:34:31 -0000	1.39
+++ app_agi.c	20 May 2004 16:30:10 -0000	1.40
@@ -692,15 +692,17 @@
 	    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 @@
 	    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");

Index: app_groupcount.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_groupcount.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- app_groupcount.c	9 May 2004 07:51:44 -0000	1.3
+++ app_groupcount.c	20 May 2004 16:30:10 -0000	1.4
@@ -58,20 +58,17 @@
 
 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;

Index: app_setcdruserfield.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_setcdruserfield.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- app_setcdruserfield.c	9 May 2004 07:51:44 -0000	1.4
+++ app_setcdruserfield.c	20 May 2004 16:30:10 -0000	1.5
@@ -76,11 +76,12 @@
 		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 @@
 		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;
 }

Index: app_softhangup.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_softhangup.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- app_softhangup.c	23 Apr 2003 19:09:13 -0000	1.2
+++ app_softhangup.c	20 May 2004 16:30:10 -0000	1.3
@@ -47,13 +47,15 @@
 		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);
 

Index: app_zapscan.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_zapscan.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app_zapscan.c	29 Apr 2004 02:30:14 -0000	1.9
+++ app_zapscan.c	20 May 2004 16:30:10 -0000	1.10
@@ -54,17 +54,18 @@
 
 #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 @@
                 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;
 }




More information about the svn-commits mailing list