[asterisk-commits] kpfleming: branch 1.2 r47802 - /branches/1.2/channel.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Nov 17 12:02:10 MST 2006


Author: kpfleming
Date: Fri Nov 17 13:02:09 2006
New Revision: 47802

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47802
Log:
backport proper channel_find_locked behavior from 1.4 branch (noted by Steve Davies on asterisk-dev list)

Modified:
    branches/1.2/channel.c

Modified: branches/1.2/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channel.c?view=diff&rev=47802&r1=47801&r2=47802
==============================================================================
--- branches/1.2/channel.c (original)
+++ branches/1.2/channel.c Fri Nov 17 13:02:09 2006
@@ -732,43 +732,34 @@
 					       const char *context, const char *exten)
 {
 	const char *msg = prev ? "deadlock" : "initial deadlock";
-	int retries, done;
+	int retries;
 	struct ast_channel *c;
 
 	for (retries = 0; retries < 10; retries++) {
+		int done;
+
 		ast_mutex_lock(&chlock);
 		for (c = channels; c; c = c->next) {
-			if (!prev) {
-				/* want head of list */
-				if (!name && !exten)
-					break;
-				if (name) {
-					/* want match by full name */
-					if (!namelen) {
-						if (!strcasecmp(c->name, name))
-							break;
-						else
-							continue;
-					}
-					/* want match by name prefix */
-					if (!strncasecmp(c->name, name, namelen))
-						break;
-				} else if (exten) {
-					/* want match by context and exten */
-					if (context && (strcasecmp(c->context, context) &&
-							strcasecmp(c->macrocontext, context)))
-						continue;
-					/* match by exten */
-					if (strcasecmp(c->exten, exten) &&
-					    strcasecmp(c->macroexten, exten))
-						continue;
-					else
-						break;
-				}
-			} else if (c == prev) { /* found, return c->next */
+			if (prev) {	/* look for next item */
+				if (c != prev)	/* not this one */
+					continue;
+				/* found, prepare to return c->next */
 				c = c->next;
-				break;
 			}
+			if (name) { /* want match by name */
+				if ((!namelen && strcasecmp(c->name, name)) ||
+				    (namelen && strncasecmp(c->name, name, namelen)))
+					continue;	/* name match failed */
+			} else if (exten) {
+				if (context && strcasecmp(c->context, context) &&
+				    strcasecmp(c->macrocontext, context))
+					continue;	/* context match failed */
+				if (strcasecmp(c->exten, exten) &&
+				    strcasecmp(c->macroexten, exten))
+					continue;	/* exten match failed */
+			}
+			/* if we get here, c points to the desired record */
+			break;
 		}
 		/* exit if chan not found or mutex acquired successfully */
 		done = (c == NULL) || (ast_mutex_trylock(&c->lock) == 0);



More information about the asterisk-commits mailing list