[asterisk-commits] tilghman: branch 1.6.0 r118958 - in /branches/1.6.0: ./ channels/ include/ast...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 29 12:42:29 CDT 2008


Author: tilghman
Date: Thu May 29 12:42:28 2008
New Revision: 118958

URL: http://svn.digium.com/view/asterisk?view=rev&rev=118958
Log:
Merged revisions 118955,118957 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r118955 | tilghman | 2008-05-29 12:35:19 -0500 (Thu, 29 May 2008) | 11 lines

Merged revisions 118953 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r118953 | tilghman | 2008-05-29 12:20:16 -0500 (Thu, 29 May 2008) | 3 lines

Add some debugging code that ensures that when we do deadlock avoidance, we
don't lose the information about how a lock was originally acquired.

........

................
r118957 | tilghman | 2008-05-29 12:39:50 -0500 (Thu, 29 May 2008) | 10 lines

Merged revisions 118954 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r118954 | tilghman | 2008-05-29 12:33:01 -0500 (Thu, 29 May 2008) | 2 lines

Define also when not DEBUG_THREADS

........

................

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/channels/chan_agent.c
    branches/1.6.0/channels/chan_alsa.c
    branches/1.6.0/channels/chan_iax2.c
    branches/1.6.0/channels/chan_mgcp.c
    branches/1.6.0/channels/chan_zap.c
    branches/1.6.0/include/asterisk/lock.h
    branches/1.6.0/main/utils.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/channels/chan_agent.c?view=diff&rev=118958&r1=118957&r2=118958
==============================================================================
--- branches/1.6.0/channels/chan_agent.c (original)
+++ branches/1.6.0/channels/chan_agent.c Thu May 29 12:42:28 2008
@@ -1520,9 +1520,7 @@
 					ast_mutex_lock(&p->lock);
 
 					while (p->owner && ast_channel_trylock(p->owner)) {
-						ast_mutex_unlock(&p->lock);
-						usleep(1);
-						ast_mutex_lock(&p->lock);
+						DEADLOCK_AVOIDANCE(&p->lock);
 					}
 					if (p->owner) {
 						ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
@@ -1530,9 +1528,7 @@
 					}
 
 					while (p->chan && ast_channel_trylock(p->chan)) {
-						ast_mutex_unlock(&p->lock);
-						usleep(1);
-						ast_mutex_lock(&p->lock);
+						DEADLOCK_AVOIDANCE(&p->lock);
 					}
 					if (p->chan) {
 						ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);

Modified: branches/1.6.0/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/channels/chan_alsa.c?view=diff&rev=118958&r1=118957&r2=118958
==============================================================================
--- branches/1.6.0/channels/chan_alsa.c (original)
+++ branches/1.6.0/channels/chan_alsa.c Thu May 29 12:42:28 2008
@@ -297,9 +297,7 @@
 static void grab_owner(void)
 {
 	while (alsa.owner && ast_channel_trylock(alsa.owner)) {
-		ast_mutex_unlock(&alsalock);
-		usleep(1);
-		ast_mutex_lock(&alsalock);
+		DEADLOCK_AVOIDANCE(&alsalock);
 	}
 }
 

Modified: branches/1.6.0/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/channels/chan_iax2.c?view=diff&rev=118958&r1=118957&r2=118958
==============================================================================
--- branches/1.6.0/channels/chan_iax2.c (original)
+++ branches/1.6.0/channels/chan_iax2.c Thu May 29 12:42:28 2008
@@ -1734,9 +1734,7 @@
 		if (iaxs[callno] && iaxs[callno]->owner) {
 			if (ast_channel_trylock(iaxs[callno]->owner)) {
 				/* Avoid deadlock by pausing and trying again */
-				ast_mutex_unlock(&iaxsl[callno]);
-				usleep(1);
-				ast_mutex_lock(&iaxsl[callno]);
+				DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			} else {
 				ast_queue_frame(iaxs[callno]->owner, f);
 				ast_channel_unlock(iaxs[callno]->owner);
@@ -1767,9 +1765,7 @@
 		if (iaxs[callno] && iaxs[callno]->owner) {
 			if (ast_channel_trylock(iaxs[callno]->owner)) {
 				/* Avoid deadlock by pausing and trying again */
-				ast_mutex_unlock(&iaxsl[callno]);
-				usleep(1);
-				ast_mutex_lock(&iaxsl[callno]);
+				DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			} else {
 				ast_queue_hangup(iaxs[callno]->owner);
 				ast_channel_unlock(iaxs[callno]->owner);
@@ -1801,9 +1797,7 @@
 		if (iaxs[callno] && iaxs[callno]->owner) {
 			if (ast_channel_trylock(iaxs[callno]->owner)) {
 				/* Avoid deadlock by pausing and trying again */
-				ast_mutex_unlock(&iaxsl[callno]);
-				usleep(1);
-				ast_mutex_lock(&iaxsl[callno]);
+				DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			} else {
 				ast_queue_control_data(iaxs[callno]->owner, control, data, datalen);
 				ast_channel_unlock(iaxs[callno]->owner);
@@ -3734,9 +3728,7 @@
 {
 	ast_mutex_lock(&iaxsl[callno0]);
 	while (ast_mutex_trylock(&iaxsl[callno1])) {
-		ast_mutex_unlock(&iaxsl[callno0]);
-		usleep(10);
-		ast_mutex_lock(&iaxsl[callno0]);
+		DEADLOCK_AVOIDANCE(&iaxsl[callno0]);
 	}
 }
 
@@ -3927,9 +3919,7 @@
 		/* We don't know the remote side's call number, yet.  :( */
 		int count = 10;
 		while (count-- && pvt && !pvt->peercallno) {
-			ast_mutex_unlock(&iaxsl[callno]);
-			usleep(1);
-			ast_mutex_lock(&iaxsl[callno]);
+			DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			pvt = iaxs[callno];
 		}
 		if (!pvt->peercallno) {
@@ -8220,9 +8210,7 @@
 						int orignative;
 retryowner:
 						if (ast_channel_trylock(iaxs[fr->callno]->owner)) {
-							ast_mutex_unlock(&iaxsl[fr->callno]);
-							usleep(1);
-							ast_mutex_lock(&iaxsl[fr->callno]);
+							DEADLOCK_AVOIDANCE(&iaxsl[fr->callno]);
 							if (iaxs[fr->callno] && iaxs[fr->callno]->owner) goto retryowner;
 						}
 						if (iaxs[fr->callno]) {
@@ -8659,9 +8647,7 @@
 						ast_verb(3, "Format for call is %s\n", ast_getformatname(iaxs[fr->callno]->owner->nativeformats));
 retryowner2:
 						if (ast_channel_trylock(iaxs[fr->callno]->owner)) {
-							ast_mutex_unlock(&iaxsl[fr->callno]);
-							usleep(1);
-							ast_mutex_lock(&iaxsl[fr->callno]);
+							DEADLOCK_AVOIDANCE(&iaxsl[fr->callno]);
 							if (iaxs[fr->callno] && iaxs[fr->callno]->owner) goto retryowner2;
 						}
 						

Modified: branches/1.6.0/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/channels/chan_mgcp.c?view=diff&rev=118958&r1=118957&r2=118958
==============================================================================
--- branches/1.6.0/channels/chan_mgcp.c (original)
+++ branches/1.6.0/channels/chan_mgcp.c Thu May 29 12:42:28 2008
@@ -594,9 +594,7 @@
 				ast_channel_unlock(sub->owner);
 				break;
 			} else {
-				ast_mutex_unlock(&sub->lock);
-				usleep(1);
-				ast_mutex_lock(&sub->lock);
+				DEADLOCK_AVOIDANCE(&sub->lock);
 			}
 		} else
 			break;
@@ -612,9 +610,7 @@
 				ast_channel_unlock(sub->owner);
 				break;
 			} else {
-				ast_mutex_unlock(&sub->lock);
-				usleep(1);
-				ast_mutex_lock(&sub->lock);
+				DEADLOCK_AVOIDANCE(&sub->lock);
 			}
 		} else
 			break;

Modified: branches/1.6.0/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/channels/chan_zap.c?view=diff&rev=118958&r1=118957&r2=118958
==============================================================================
--- branches/1.6.0/channels/chan_zap.c (original)
+++ branches/1.6.0/channels/chan_zap.c Thu May 29 12:42:28 2008
@@ -877,10 +877,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 */
@@ -971,9 +968,7 @@
 	for (;;) {
 		if (p->subs[a].owner) {
 			if (ast_channel_trylock(p->subs[a].owner)) {
-				ast_mutex_unlock(&p->lock);
-				usleep(1);
-				ast_mutex_lock(&p->lock);
+				DEADLOCK_AVOIDANCE(&p->lock);
 			} else {
 				ast_queue_frame(p->subs[a].owner, &ast_null_frame);
 				ast_channel_unlock(p->subs[a].owner);
@@ -1020,9 +1015,7 @@
 	for (;;) {
 		if (p->owner) {
 			if (ast_channel_trylock(p->owner)) {
-				ast_mutex_unlock(&p->lock);
-				usleep(1);
-				ast_mutex_lock(&p->lock);
+				DEADLOCK_AVOIDANCE(&p->lock);
 			} else {
 				ast_queue_frame(p->owner, f);
 				ast_channel_unlock(p->owner);
@@ -3637,9 +3630,7 @@
 		ast_mutex_lock(&master->lock);
 		if (slave) {
 			while (ast_mutex_trylock(&slave->lock)) {
-				ast_mutex_unlock(&master->lock);
-				usleep(1);
-				ast_mutex_lock(&master->lock);
+				DEADLOCK_AVOIDANCE(&master->lock);
 			}
 		}
 	}
@@ -10121,9 +10112,7 @@
 		for (x = 0; x < 3; x++) {
 			while (p->subs[x].owner && ast_channel_trylock(p->subs[x].owner)) {
 				redo++;
-				ast_mutex_unlock(&p->lock);
-				usleep(1);
-				ast_mutex_lock(&p->lock);
+				DEADLOCK_AVOIDANCE(&p->lock);
 			}
 			if (p->subs[x].owner) {
 				ast_queue_hangup(p->subs[x].owner);

Modified: branches/1.6.0/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/include/asterisk/lock.h?view=diff&rev=118958&r1=118957&r2=118958
==============================================================================
--- branches/1.6.0/include/asterisk/lock.h (original)
+++ branches/1.6.0/include/asterisk/lock.h Thu May 29 12:42:28 2008
@@ -185,6 +185,38 @@
 #else
 #define ast_remove_lock_info(ignore)
 #endif
+
+/*!
+ * \brief retrieve lock info for the specified mutex
+ *
+ * this gets called during deadlock avoidance, so that the information may
+ * be preserved as to what location originally acquired the lock.
+ */
+#if !defined(LOW_MEMORY)
+int ast_find_lock_info(void *lock_addr, const char **filename, int *lineno, const char **func, const char **mutex_name);
+#else
+#define ast_find_lock_info(a,b,c,d,e) -1
+#endif
+
+/*!
+ * \brief Unlock a lock briefly
+ *
+ * used during deadlock avoidance, to preserve the original location where
+ * a lock was originally acquired.
+ */
+#define DEADLOCK_AVOIDANCE(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); \
+		usleep(1); \
+		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 void __attribute__((constructor)) init_empty_mutex(void)
 {
@@ -1035,6 +1067,11 @@
 
 #else /* !DEBUG_THREADS */
 
+#define	DEADLOCK_AVOIDANCE(lock) \
+	ast_mutex_lock(lock); \
+	usleep(1); \
+	ast_mutex_unlock(lock);
+
 static inline int ast_rwlock_init(ast_rwlock_t *prwlock)
 {
 	int res;

Modified: branches/1.6.0/main/utils.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/utils.c?view=diff&rev=118958&r1=118957&r2=118958
==============================================================================
--- branches/1.6.0/main/utils.c (original)
+++ branches/1.6.0/main/utils.c Thu May 29 12:42:28 2008
@@ -662,6 +662,34 @@
 	pthread_mutex_unlock(&lock_info->lock);
 }
 
+int ast_find_lock_info(void *lock_addr, const char **filename, int *lineno, const char **func, const char **mutex_name)
+{
+	struct thr_lock_info *lock_info;
+	int i = 0;
+
+	if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
+		return -1;
+
+	pthread_mutex_lock(&lock_info->lock);
+
+	for (i = lock_info->num_locks - 1; i >= 0; i--) {
+		if (lock_info->locks[i].lock_addr == lock_addr)
+			break;
+	}
+
+	if (i == -1) {
+		/* Lock not found :( */
+		pthread_mutex_unlock(&lock_info->lock);
+		return -1;
+	}
+
+	*filename = lock_info->locks[i].file;
+	*lineno = lock_info->locks[i].line_num;
+	*func = lock_info->locks[i].func;
+	*mutex_name = lock_info->locks[i].lock_name;
+	return 0;
+}
+
 void ast_remove_lock_info(void *lock_addr)
 {
 	struct thr_lock_info *lock_info;




More information about the asterisk-commits mailing list