[Asterisk-cvs] asterisk channel.c,1.111,1.112 cli.c,1.38,1.39 manager.c,1.47,1.48 pbx.c,1.121,1.122

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


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

Modified Files:
	channel.c cli.c manager.c pbx.c 
Log Message:
Make ast_channel_walk become ast_channel_walk_locked


Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -d -r1.111 -r1.112
--- channel.c	20 May 2004 00:29:09 -0000	1.111
+++ channel.c	20 May 2004 16:30:09 -0000	1.112
@@ -444,12 +444,15 @@
 		chan->deferdtmf = 0;
 }
 
-struct ast_channel *ast_channel_walk(struct ast_channel *prev)
+struct ast_channel *ast_channel_walk_locked(struct ast_channel *prev)
 {
+	/* Returns next channel (locked) */
 	struct ast_channel *l, *ret=NULL;
 	ast_mutex_lock(&chlock);
 	l = channels;
 	if (!prev) {
+		if (l)
+			ast_mutex_lock(&l->lock);
 		ast_mutex_unlock(&chlock);
 		return l;
 	}
@@ -458,6 +461,8 @@
 			ret = l->next;
 		l = l->next;
 	}
+	if (ret)
+		ast_mutex_lock(&ret->lock);
 	ast_mutex_unlock(&chlock);
 	return ret;
 	
@@ -527,6 +532,12 @@
 	}
 	if (!cur)
 		ast_log(LOG_WARNING, "Unable to find channel in list\n");
+	else {
+		/* Lock and unlock the channel just to be sure nobody
+		   has it locked still */
+		ast_mutex_lock(&cur->lock);
+		ast_mutex_unlock(&cur->lock);
+	}
 	if (chan->pvt->pvt)
 		ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name);
 
@@ -1798,15 +1809,16 @@
 	char *cut;
 	struct ast_channel *chan;
 
-	chan = ast_channel_walk(NULL);
+	chan = ast_channel_walk_locked(NULL);
 	while (chan) {
 		strncpy(name, chan->name, sizeof(name)-1);
+		ast_mutex_unlock(&chan->lock);
 		cut = strchr(name,'-');
 		if (cut)
 		        *cut = 0;
 		if (!strcmp(name, device))
 		        return AST_DEVICE_INUSE;
-		chan = ast_channel_walk(chan);
+		chan = ast_channel_walk_locked(chan);
 	}
 	return AST_DEVICE_UNKNOWN;
 }

Index: cli.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cli.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- cli.c	10 May 2004 18:45:20 -0000	1.38
+++ cli.c	20 May 2004 16:30:09 -0000	1.39
@@ -291,13 +291,14 @@
 	int numchans = 0;
 	if (argc != 2)
 		return RESULT_SHOWUSAGE;
-	c = ast_channel_walk(NULL);
+	c = ast_channel_walk_locked(NULL);
 	ast_cli(fd, FORMAT_STRING2, "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data");
 	while(c) {
 		ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
 		c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)");
 		numchans++;
-		c = ast_channel_walk(c);
+		ast_mutex_unlock(&c->lock);
+		c = ast_channel_walk_locked(c);
 	}
 	ast_cli(fd, "%d active channel(s)\n", numchans);
 	return RESULT_SUCCESS;
@@ -335,14 +336,16 @@
 	struct ast_channel *c=NULL;
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
-	c = ast_channel_walk(NULL);
+	c = ast_channel_walk_locked(NULL);
 	while(c) {
 		if (!strcasecmp(c->name, argv[2])) {
 			ast_cli(fd, "Requested Hangup on channel '%s'\n", c->name);
 			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);
 	}
 	if (!c) 
 		ast_cli(fd, "%s is not a known channel\n", argv[2]);
@@ -438,17 +441,20 @@
 	struct ast_channel *c=NULL;
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
-	c = ast_channel_walk(NULL);
+	c = ast_channel_walk_locked(NULL);
 	while(c) {
 		if (!strcasecmp(c->name, argv[2])) {
 			c->fin |= 0x80000000;
 			c->fout |= 0x80000000;
 			break;
 		}
-		c = ast_channel_walk(c);
+		ast_mutex_unlock(&c->lock);
+		c = ast_channel_walk_locked(c);
 	}
-	if (c)
+	if (c) {
 		ast_cli(fd, "Debugging enabled on channel %s\n", c->name);
+		ast_mutex_unlock(&c->lock);
+	}
 	else
 		ast_cli(fd, "No such channel %s\n", argv[2]);
 	return RESULT_SUCCESS;
@@ -459,18 +465,20 @@
 	struct ast_channel *c=NULL;
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
-	c = ast_channel_walk(NULL);
+	c = ast_channel_walk_locked(NULL);
 	while(c) {
 		if (!strcasecmp(c->name, argv[3])) {
 			c->fin &= 0x7fffffff;
 			c->fout &= 0x7fffffff;
 			break;
 		}
-		c = ast_channel_walk(c);
+		ast_mutex_unlock(&c->lock);
+		c = ast_channel_walk_locked(c);
 	}
-	if (c)
+	if (c) {
 		ast_cli(fd, "Debugging disabled on channel %s\n", c->name);
-	else
+		ast_mutex_unlock(&c->lock);
+	} else
 		ast_cli(fd, "No such channel %s\n", argv[2]);
 	return RESULT_SUCCESS;
 }
@@ -482,7 +490,7 @@
 	struct ast_channel *c=NULL;
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
-	c = ast_channel_walk(NULL);
+	c = ast_channel_walk_locked(NULL);
 	while(c) {
 		if (!strcasecmp(c->name, argv[2])) {
 			ast_cli(fd, 
@@ -519,10 +527,11 @@
 	c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
 	( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
 	c->stack, (c->blocking ? c->blockproc : "(Not Blocking)"));
-	
+		ast_mutex_unlock(&c->lock);
 		break;
 		}
-		c = ast_channel_walk(c);
+		ast_mutex_unlock(&c->lock);
+		c = ast_channel_walk_locked(c);
 	}
 	if (!c) 
 		ast_cli(fd, "%s is not a known channel\n", argv[2]);
@@ -533,15 +542,22 @@
 {
 	struct ast_channel *c;
 	int which=0;
-	c = ast_channel_walk(NULL);
+	char *ret;
+	c = ast_channel_walk_locked(NULL);
 	while(c) {
 		if (!strncasecmp(word, c->name, strlen(word))) {
 			if (++which > state)
 				break;
 		}
-		c = ast_channel_walk(c);
+		ast_mutex_unlock(&c->lock);
+		c = ast_channel_walk_locked(c);
 	}
-	return c ? strdup(c->name) : NULL;
+	if (c) {
+		ret = strdup(c->name);
+		ast_mutex_unlock(&c->lock);
+	} else
+		ret = NULL;
+	return ret;
 }
 
 static char *complete_fn(char *line, char *word, int pos, int state)

Index: manager.c
===================================================================
RCS file: /usr/cvsroot/asterisk/manager.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- manager.c	1 May 2004 23:52:27 -0000	1.47
+++ manager.c	20 May 2004 16:30:09 -0000	1.48
@@ -376,18 +376,20 @@
 		astman_send_error(s, m, "No channel specified");
 		return 0;
 	}
-	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) {
 		astman_send_error(s, m, "No such channel");
 		return 0;
 	}
 	ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
+	ast_mutex_unlock(&c->lock);
 	astman_send_ack(s, m, "Channel Hungup");
 	return 0;
 }
@@ -399,7 +401,7 @@
 	struct ast_channel *c;
 	char bridge[256];
 	astman_send_ack(s, m, "Channel status will follow");
-	c = ast_channel_walk(NULL);
+	c = ast_channel_walk_locked(NULL);
         if (id && strlen(id))
                 snprintf(idText,256,"ActionID: %s\r\n",id);
 	while(c) {
@@ -436,7 +438,8 @@
 			c->name, c->callerid ? c->callerid : "<unknown>", 
 			ast_state2str(c->_state), bridge, c->uniqueid, idText);
 		}
-		c = ast_channel_walk(c);
+		ast_mutex_unlock(&c->lock);
+		c = ast_channel_walk_locked(c);
 	}
 	ast_cli(s->fd,
 	"Event: StatusComplete\r\n"
@@ -688,18 +691,20 @@
 		astman_send_error(s, m, "No timeout specified");
 		return 0;
 	}
-	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) {
 		astman_send_error(s, m, "No such channel");
 		return 0;
 	}
 	ast_channel_setwhentohangup(c, timeout);
+	ast_mutex_unlock(&c->lock);
 	astman_send_ack(s, m, "Timeout Set");
 	return 0;
 }

Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- pbx.c	17 May 2004 21:15:37 -0000	1.121
+++ pbx.c	20 May 2004 16:30:09 -0000	1.122
@@ -3592,15 +3592,21 @@
 int ast_async_goto_by_name(char *channame, char *context, char *exten, int priority)
 {
 	struct ast_channel *chan;
-	chan = ast_channel_walk(NULL);
+	int res = -1;
+
+	chan = ast_channel_walk_locked(NULL);
 	while(chan) {
 		if (!strcasecmp(channame, chan->name))
 			break;
-		chan = ast_channel_walk(chan);
+		ast_mutex_unlock(&chan->lock);
+		chan = ast_channel_walk_locked(chan);
 	}
-	if (chan)
-		return ast_async_goto(chan, context, exten, priority);
-	return -1;
+	
+	if (chan) {
+		res = ast_async_goto(chan, context, exten, priority);
+		ast_mutex_unlock(&chan->lock);
+	}
+	return res;
 }
 
 static void ext_strncpy(char *dst, char *src, int len)




More information about the svn-commits mailing list