[Asterisk-cvs] asterisk/res res_agi.c, 1.36, 1.37 res_features.c, 1.55, 1.56 res_monitor.c, 1.33, 1.34 res_musiconhold.c, 1.58, 1.59

kpfleming at lists.digium.com kpfleming at lists.digium.com
Sun Jun 5 22:26:47 CDT 2005


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

Modified Files:
	res_agi.c res_features.c res_monitor.c res_musiconhold.c 
Log Message:
more efficient (and understandable) ast_channel_walk_locked, and vastly more efficient ast_channel_by_name_locked (bug #4265)


Index: res_agi.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_agi.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- res_agi.c	5 Jun 2005 21:00:33 -0000	1.36
+++ res_agi.c	6 Jun 2005 02:29:18 -0000	1.37
@@ -960,19 +960,15 @@
 		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 @@
 		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 @@
 	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 {

Index: res_features.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_features.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- res_features.c	3 Jun 2005 12:50:05 -0000	1.55
+++ res_features.c	6 Jun 2005 02:29:18 -0000	1.56
@@ -1661,10 +1661,9 @@
 
 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 @@
 			 	break;
 		}
 		ast_mutex_unlock(&cur->lock);
-		cur = ast_channel_walk_locked(cur);
 	}
 	if (cur) {
 		if (option_debug)

Index: res_monitor.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_monitor.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- res_monitor.c	6 May 2005 07:15:08 -0000	1.33
+++ res_monitor.c	6 Jun 2005 02:29:18 -0000	1.34
@@ -413,14 +413,7 @@
 		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 @@
 		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 @@
 		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;

Index: res_musiconhold.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_musiconhold.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- res_musiconhold.c	21 Apr 2005 06:02:44 -0000	1.58
+++ res_musiconhold.c	6 Jun 2005 02:29:18 -0000	1.59
@@ -962,10 +962,11 @@
 	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 @@
 				ast_deactivate_generator(chan);
 		}
 		ast_mutex_unlock(&chan->lock);
-		chan = ast_channel_walk_locked(chan);
 	}
 }
 




More information about the svn-commits mailing list