[asterisk-commits] rmudgett: trunk r367979 - in /trunk: ./ channels/sig_pri.c channels/sig_ss7.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 30 12:50:42 CDT 2012


Author: rmudgett
Date: Wed May 30 12:50:38 2012
New Revision: 367979

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367979
Log:
Fix deadlock when executing CLI "pri show channels" and  "ss7 show channels" commands.

* Fix sig_pri_lock_owner() to avoid deadlock properly.

* Code pri_grab() better.

* Fix sig_ss7_lock_owner() to avoid deadlock properly.

* Code ss7_grab() better.

(closes issue ASTERISK-19854)
Reported by: Jaxon
Patches:
      jira_asterisk_19854_v1.8.6.patch (license #5621) patch uploaded by rmudgett (Modified to do the same thing to sig_ss7)
Tested by: Jaxon
........

Merged revisions 367976 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 367978 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/channels/sig_pri.c
    trunk/channels/sig_ss7.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/sig_pri.c?view=diff&rev=367979&r1=367978&r2=367979
==============================================================================
--- trunk/channels/sig_pri.c (original)
+++ trunk/channels/sig_pri.c Wed May 30 12:50:38 2012
@@ -115,13 +115,6 @@
 
 #define DCHAN_AVAILABLE	(DCHAN_NOTINALARM | DCHAN_UP)
 
-#define PRI_DEADLOCK_AVOIDANCE(p) \
-	do { \
-		sig_pri_unlock_private(p); \
-		usleep(1); \
-		sig_pri_lock_private(p); \
-	} while (0)
-
 static int pri_active_dchan_index(struct sig_pri_span *pri);
 
 static const char *sig_pri_call_level2str(enum sig_pri_call_level level)
@@ -349,23 +342,23 @@
 		p->calls->deadlock_avoidance_private(p->chan_pvt);
 	} else {
 		/* Fallback to the old way if callback not present. */
-		PRI_DEADLOCK_AVOIDANCE(p);
+		sig_pri_unlock_private(p);
+		sched_yield();
+		sig_pri_lock_private(p);
 	}
 }
 
 static void pri_grab(struct sig_pri_chan *p, struct sig_pri_span *pri)
 {
-	int res;
-
 	/* Grab the lock first */
-	do {
-		res = ast_mutex_trylock(&pri->lock);
-		if (res) {
-			sig_pri_deadlock_avoidance_private(p);
-		}
-	} while (res);
+	while (ast_mutex_trylock(&pri->lock)) {
+		/* Avoid deadlock */
+		sig_pri_deadlock_avoidance_private(p);
+	}
 	/* Then break the poll */
-	pthread_kill(pri->master, SIGURG);
+	if (pri->master != AST_PTHREADT_NULL) {
+		pthread_kill(pri->master, SIGURG);
+	}
 }
 
 /*!
@@ -1205,10 +1198,11 @@
 			/* We got the lock */
 			break;
 		}
-		/* We must unlock the PRI to avoid the possibility of a deadlock */
-		ast_mutex_unlock(&pri->lock);
-		sig_pri_deadlock_avoidance_private(pri->pvts[chanpos]);
-		ast_mutex_lock(&pri->lock);
+
+		/* Avoid deadlock */
+		sig_pri_unlock_private(pri->pvts[chanpos]);
+		DEADLOCK_AVOIDANCE(&pri->lock);
+		sig_pri_lock_private(pri->pvts[chanpos]);
 	}
 }
 

Modified: trunk/channels/sig_ss7.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/sig_ss7.c?view=diff&rev=367979&r1=367978&r2=367979
==============================================================================
--- trunk/channels/sig_ss7.c (original)
+++ trunk/channels/sig_ss7.c Wed May 30 12:50:38 2012
@@ -67,13 +67,6 @@
 	return "Unknown";
 }
 
-#define SIG_SS7_DEADLOCK_AVOIDANCE(p) \
-	do { \
-		sig_ss7_unlock_private(p); \
-		usleep(1); \
-		sig_ss7_lock_private(p); \
-	} while (0)
-
 static void sig_ss7_unlock_private(struct sig_ss7_chan *p)
 {
 	if (p->calls->unlock_private) {
@@ -94,7 +87,9 @@
 		p->calls->deadlock_avoidance_private(p->chan_pvt);
 	} else {
 		/* Fallback to the old way if callback not present. */
-		SIG_SS7_DEADLOCK_AVOIDANCE(p);
+		sig_ss7_unlock_private(p);
+		sched_yield();
+		sig_ss7_lock_private(p);
 	}
 }
 
@@ -314,10 +309,11 @@
 			/* We got the lock */
 			break;
 		}
-		/* We must unlock the SS7 to avoid the possibility of a deadlock */
-		ast_mutex_unlock(&ss7->lock);
-		sig_ss7_deadlock_avoidance_private(ss7->pvts[chanpos]);
-		ast_mutex_lock(&ss7->lock);
+
+		/* Avoid deadlock */
+		sig_ss7_unlock_private(ss7->pvts[chanpos]);
+		DEADLOCK_AVOIDANCE(&ss7->lock);
+		sig_ss7_lock_private(ss7->pvts[chanpos]);
 	}
 }
 
@@ -1266,17 +1262,15 @@
 
 static void ss7_grab(struct sig_ss7_chan *pvt, struct sig_ss7_linkset *ss7)
 {
-	int res;
 	/* Grab the lock first */
-	do {
-		res = ast_mutex_trylock(&ss7->lock);
-		if (res) {
-			sig_ss7_deadlock_avoidance_private(pvt);
-		}
-	} while (res);
+	while (ast_mutex_trylock(&ss7->lock)) {
+		/* Avoid deadlock */
+		sig_ss7_deadlock_avoidance_private(pvt);
+	}
 	/* Then break the poll */
-	if (ss7->master != AST_PTHREADT_NULL)
+	if (ss7->master != AST_PTHREADT_NULL) {
 		pthread_kill(ss7->master, SIGURG);
+	}
 }
 
 /*!




More information about the asterisk-commits mailing list