[svn-commits] tilghman: trunk r125020 - in /trunk: channels/ include/asterisk/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 24 21:34:13 CDT 2008


Author: tilghman
Date: Tue Jun 24 21:34:11 2008
New Revision: 125020

URL: http://svn.digium.com/view/asterisk?view=rev&rev=125020
Log:
More expansion of the deadlock avoidance macro, including a macro to do locking
of the channel lock

Modified:
    trunk/channels/chan_dahdi.c
    trunk/channels/chan_features.c
    trunk/channels/chan_h323.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_local.c
    trunk/include/asterisk/lock.h

Modified: trunk/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_dahdi.c?view=diff&rev=125020&r1=125019&r2=125020
==============================================================================
--- trunk/channels/chan_dahdi.c (original)
+++ trunk/channels/chan_dahdi.c Tue Jun 24 21:34:11 2008
@@ -898,10 +898,7 @@
 	do {
 		res = ast_mutex_trylock(&pri->lock);
 		if (res) {
-			ast_mutex_unlock(&pvt->lock);
-			/* Release the lock and try again */
-			usleep(1);
-			ast_mutex_lock(&pvt->lock);
+			DEADLOCK_AVOIDANCE(&pvt->lock);
 		}
 	} while (res);
 	/* Then break the poll */
@@ -3755,9 +3752,7 @@
 
 	ast_channel_lock(c0);
 	while (ast_channel_trylock(c1)) {
-		ast_channel_unlock(c0);
-		usleep(1);
-		ast_channel_lock(c0);
+		CHANNEL_DEADLOCK_AVOIDANCE(c0);
 	}
 
 	p0 = c0->tech_pvt;
@@ -3927,9 +3922,7 @@
 		
 		ast_channel_lock(c0);
 		while (ast_channel_trylock(c1)) {
-			ast_channel_unlock(c0);
-			usleep(1);
-			ast_channel_lock(c0);
+			CHANNEL_DEADLOCK_AVOIDANCE(c0);
 		}
 
 		p0 = c0->tech_pvt;
@@ -4469,14 +4462,12 @@
 						   the private structure -- not especially easy or clean */
 						while (p->subs[SUB_THREEWAY].owner && ast_channel_trylock(p->subs[SUB_THREEWAY].owner)) {
 							/* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
-							ast_mutex_unlock(&p->lock);
-							ast_channel_unlock(ast);
-							usleep(1);
+							DLA_UNLOCK(&p->lock);
+							CHANNEL_DEADLOCK_AVOIDANCE(ast);
 							/* We can grab ast and p in that order, without worry.  We should make sure
 							   nothing seriously bad has happened though like some sort of bizarre double
 							   masquerade! */
-							ast_channel_lock(ast);
-							ast_mutex_lock(&p->lock);
+							DLA_LOCK(&p->lock);
 							if (p->owner != ast) {
 								ast_log(LOG_WARNING, "This isn't good...\n");
 								return NULL;

Modified: trunk/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_features.c?view=diff&rev=125020&r1=125019&r2=125020
==============================================================================
--- trunk/channels/chan_features.c (original)
+++ trunk/channels/chan_features.c Tue Jun 24 21:34:11 2008
@@ -139,9 +139,7 @@
 	for (;;) {
 		if (p->subs[a].owner) {
 			if (ast_mutex_trylock(&p->subs[a].owner->lock)) {
-				ast_mutex_unlock(&p->lock);
-				usleep(1);
-				ast_mutex_lock(&p->lock);
+				DEADLOCK_AVOIDANCE(&p->lock);
 			} else {
 				ast_queue_frame(p->subs[a].owner, &null);
 				ast_mutex_unlock(&p->subs[a].owner->lock);

Modified: trunk/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_h323.c?view=diff&rev=125020&r1=125019&r2=125020
==============================================================================
--- trunk/channels/chan_h323.c (original)
+++ trunk/channels/chan_h323.c Tue Jun 24 21:34:11 2008
@@ -304,9 +304,7 @@
 		ast_mutex_lock(&pvt->lock);
 		/* Don't hold pvt lock while trying to lock the channel */
 		while(pvt->owner && ast_channel_trylock(pvt->owner)) {
-			ast_mutex_unlock(&pvt->lock);
-			usleep(1);
-			ast_mutex_lock(&pvt->lock);
+			DEADLOCK_AVOIDANCE(&pvt->lock);
 		}
 
 		if (pvt->owner) {

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=125020&r1=125019&r2=125020
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Tue Jun 24 21:34:11 2008
@@ -2248,9 +2248,7 @@
 	if (owner) {
 		if (ast_channel_trylock(owner)) {
 			ast_debug(3, "Avoiding IAX destroy deadlock\n");
-			ast_mutex_unlock(&iaxsl[callno]);
-			usleep(1);
-			ast_mutex_lock(&iaxsl[callno]);
+			DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			goto retry;
 		}
 	}

Modified: trunk/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_local.c?view=diff&rev=125020&r1=125019&r2=125020
==============================================================================
--- trunk/channels/chan_local.c (original)
+++ trunk/channels/chan_local.c Tue Jun 24 21:34:11 2008
@@ -219,15 +219,13 @@
 
 	/* Ensure that we have both channels locked */
 	while (other && ast_channel_trylock(other)) {
-		ast_mutex_unlock(&p->lock);
+		DLA_UNLOCK(&p->lock);
 		if (us && us_locked) {
-			ast_channel_unlock(us);
-		}
-		usleep(1);
-		if (us && us_locked) {
-			ast_channel_lock(us);
-		}
-		ast_mutex_lock(&p->lock);
+			CHANNEL_DEADLOCK_AVOIDANCE(us);
+		} else {
+			usleep(1);
+		}
+		DLA_LOCK(&p->lock);
 		other = isoutbound ? p->owner : p->chan;
 	}
 

Modified: trunk/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/lock.h?view=diff&rev=125020&r1=125019&r2=125020
==============================================================================
--- trunk/include/asterisk/lock.h (original)
+++ trunk/include/asterisk/lock.h Tue Jun 24 21:34:11 2008
@@ -289,6 +289,21 @@
 		} \
 	} while (0)
 
+#define DLA_UNLOCK(lock) \
+	do { \
+		const char *__filename, *__func, *__mutex_name; \
+		int __lineno; \
+		int __res = ast_find_lock_info(lock, &__filename, &__lineno, &__func, &__mutex_name); \
+		ast_mutex_unlock(lock);
+
+#define DLA_LOCK(lock) \
+		if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \
+			ast_mutex_lock(lock); \
+		} else { \
+			__ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+		} \
+	} while (0)
+
 static inline void ast_reentrancy_lock(struct ast_lock_track *lt)
 {
 	pthread_mutex_lock(&lt->reentr_mutex);
@@ -1428,6 +1443,10 @@
 	ast_mutex_lock(lock); \
 	usleep(1); \
 	ast_mutex_unlock(lock);
+
+#define DLA_UNLOCK(lock)	ast_mutex_unlock(lock)
+
+#define DLA_LOCK(lock)	ast_mutex_lock(lock)
 
 typedef pthread_mutex_t ast_mutex_t;
 




More information about the svn-commits mailing list