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

markster at lists.digium.com markster at lists.digium.com
Tue Jun 29 07:05:08 CDT 2004


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

Modified Files:
	channel.c 
Log Message:
Avoid potential deadlocks in channel_walk_locked, and detect serious failures


Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -d -r1.124 -r1.125
--- channel.c	29 Jun 2004 04:42:19 -0000	1.124
+++ channel.c	29 Jun 2004 10:51:00 -0000	1.125
@@ -452,6 +452,8 @@
 {
 	/* Returns next channel (locked) */
 	struct ast_channel *l, *ret=NULL;
+	int retries = 0;	
+retry:
 	ast_mutex_lock(&chlock);
 	l = channels;
 	if (!prev) {
@@ -465,8 +467,21 @@
 			ret = l->next;
 		l = l->next;
 	}
-	if (ret)
-		ast_mutex_lock(&ret->lock);
+	if (ret) {
+		if (ast_mutex_trylock(&ret->lock)) {
+			if (retries < 10)
+				ast_log(LOG_DEBUG, "Avoiding deadlock for '%s'\n", ret->name);
+			else
+				ast_log(LOG_WARNING, "Avoided 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 ret;
 	




More information about the svn-commits mailing list