[Asterisk-cvs] asterisk channel.c,1.125,1.126

markster at lists.digium.com markster at lists.digium.com
Tue Jun 29 08:52:13 CDT 2004


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

Modified Files:
	channel.c 
Log Message:
Perform deadlock avoidance on initial entry, too


Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -d -r1.125 -r1.126
--- channel.c	29 Jun 2004 10:51:00 -0000	1.125
+++ channel.c	29 Jun 2004 12:38:04 -0000	1.126
@@ -451,14 +451,28 @@
 struct ast_channel *ast_channel_walk_locked(struct ast_channel *prev)
 {
 	/* Returns next channel (locked) */
-	struct ast_channel *l, *ret=NULL;
+	struct ast_channel *l, *ret;
 	int retries = 0;	
 retry:
+	ret=NULL;
 	ast_mutex_lock(&chlock);
 	l = channels;
 	if (!prev) {
-		if (l)
-			ast_mutex_lock(&l->lock);
+		if (l) {
+			if (ast_mutex_trylock(&l->lock)) {
+				if (retries < 10)
+					ast_log(LOG_DEBUG, "Avoiding initial deadlock for '%s'\n", ret->name);
+				else
+					ast_log(LOG_WARNING, "Avoided initial deadlock for '%s', %d retries!\n", ret->name, retries);
+				ast_mutex_unlock(&chlock);
+				if (retries < 10) {
+					usleep(1);
+					retries++;
+					goto retry;
+				} else
+					return NULL;
+			}
+		}
 		ast_mutex_unlock(&chlock);
 		return l;
 	}




More information about the svn-commits mailing list