[svn-commits] tilghman: branch 1.6.2 r273831 - in /branches/1.6.2: ./ channels/ include/ast...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jul 2 21:43:12 CDT 2010


Author: tilghman
Date: Fri Jul  2 21:43:06 2010
New Revision: 273831

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=273831
Log:
Merged revisions 273830 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r273830 | tilghman | 2010-07-02 21:36:31 -0500 (Fri, 02 Jul 2010) | 16 lines
  
  Merged revisions 273793 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r273793 | tilghman | 2010-07-02 16:36:39 -0500 (Fri, 02 Jul 2010) | 9 lines
    
    Have the DEADLOCK_AVOIDANCE macro warn when an unlock fails, to help catch potentially large software bugs.
    
    (closes issue #17407)
     Reported by: pdf
     Patches: 
           20100527__issue17407.diff.txt uploaded by tilghman (license 14)
     
    Review: https://reviewboard.asterisk.org/r/751/
  ........
................

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/channels/chan_agent.c
    branches/1.6.2/channels/chan_h323.c
    branches/1.6.2/channels/chan_local.c
    branches/1.6.2/include/asterisk/lock.h

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

Modified: branches/1.6.2/channels/chan_agent.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/channels/chan_agent.c?view=diff&rev=273831&r1=273830&r2=273831
==============================================================================
--- branches/1.6.2/channels/chan_agent.c (original)
+++ branches/1.6.2/channels/chan_agent.c Fri Jul  2 21:43:06 2010
@@ -733,7 +733,12 @@
 	ast_mutex_lock(&p->lock);
 	if (p->chan && !ast_check_hangup(p->chan)) {
 		while (ast_channel_trylock(p->chan)) {
-			ast_channel_unlock(ast);
+			int res;
+			if ((res = ast_channel_unlock(ast))) {
+				ast_log(LOG_ERROR, "chan_agent bug! Channel was not locked upon entry to agent_indicate: %s\n", strerror(res));
+				ast_mutex_unlock(&p->lock);
+				return -1;
+			}
 			usleep(1);
 			ast_channel_lock(ast);
 		}

Modified: branches/1.6.2/channels/chan_h323.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/channels/chan_h323.c?view=diff&rev=273831&r1=273830&r2=273831
==============================================================================
--- branches/1.6.2/channels/chan_h323.c (original)
+++ branches/1.6.2/channels/chan_h323.c Fri Jul  2 21:43:06 2010
@@ -306,7 +306,7 @@
 	if (pvt) {
 		ast_mutex_lock(&pvt->lock);
 		/* Don't hold pvt lock while trying to lock the channel */
-		while(pvt->owner && ast_channel_trylock(pvt->owner)) {
+		while (pvt->owner && ast_channel_trylock(pvt->owner)) {
 			DEADLOCK_AVOIDANCE(&pvt->lock);
 		}
 

Modified: branches/1.6.2/channels/chan_local.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/channels/chan_local.c?view=diff&rev=273831&r1=273830&r2=273831
==============================================================================
--- branches/1.6.2/channels/chan_local.c (original)
+++ branches/1.6.2/channels/chan_local.c Fri Jul  2 21:43:06 2010
@@ -225,7 +225,11 @@
 
 	/* Ensure that we have both channels locked */
 	while (other && ast_channel_trylock(other)) {
-		ast_mutex_unlock(&p->lock);
+		int res;
+		if ((res = ast_mutex_unlock(&p->lock))) {
+			ast_log(LOG_ERROR, "chan_local bug! '&p->lock' was not locked when entering local_queue_frame! (%s)\n", strerror(res));
+			return -1;
+		}
 		if (us && us_locked) {
 			do {
 				CHANNEL_DEADLOCK_AVOIDANCE(us);

Modified: branches/1.6.2/include/asterisk/lock.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/include/asterisk/lock.h?view=diff&rev=273831&r1=273830&r2=273831
==============================================================================
--- branches/1.6.2/include/asterisk/lock.h (original)
+++ branches/1.6.2/include/asterisk/lock.h Fri Jul  2 21:43:06 2010
@@ -59,6 +59,7 @@
 #include "asterisk/time.h"
 #endif
 #include "asterisk/logger.h"
+#include "asterisk/compiler.h"
 
 /* internal macro to profile mutexes. Only computes the delay on
  * non-blocking calls.
@@ -273,12 +274,20 @@
 		char __filename[80], __func[80], __mutex_name[80]; \
 		int __lineno; \
 		int __res = ast_find_lock_info(&chan->lock_dont_use, __filename, sizeof(__filename), &__lineno, __func, sizeof(__func), __mutex_name, sizeof(__mutex_name)); \
-		ast_channel_unlock(chan); \
+		int __res2 = ast_channel_unlock(chan); \
 		usleep(1); \
 		if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \
-			ast_channel_lock(chan); \
+			if (__res2) { \
+				ast_log(LOG_WARNING, "Could not unlock channel '%s': %s and no lock info found!  I will NOT try to relock.\n", #chan, strerror(__res2)); \
+			} else { \
+				ast_channel_lock(chan); \
+			} \
 		} else { \
-			__ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, &chan->lock_dont_use); \
+			if (__res2) { \
+				ast_log(LOG_WARNING, "Could not unlock channel '%s': %s.  {{{Originally locked at %s line %d: (%s) '%s'}}}  I will NOT try to relock.\n", #chan, strerror(__res2), __filename, __lineno, __func, __mutex_name); \
+			} else { \
+				__ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, &chan->lock_dont_use); \
+			} \
 		} \
 	} while (0)
 
@@ -287,12 +296,20 @@
 		char __filename[80], __func[80], __mutex_name[80]; \
 		int __lineno; \
 		int __res = ast_find_lock_info(lock, __filename, sizeof(__filename), &__lineno, __func, sizeof(__func), __mutex_name, sizeof(__mutex_name)); \
-		ast_mutex_unlock(lock); \
+		int __res2 = ast_mutex_unlock(lock); \
 		usleep(1); \
 		if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \
-			ast_mutex_lock(lock); \
+			if (__res2 == 0) { \
+				ast_mutex_lock(lock); \
+			} else { \
+				ast_log(LOG_WARNING, "Could not unlock mutex '%s': %s and no lock info found!  I will NOT try to relock.\n", #lock, strerror(__res2)); \
+			} \
 		} else { \
-			__ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+			if (__res2 == 0) { \
+				__ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+			} else { \
+				ast_log(LOG_WARNING, "Could not unlock mutex '%s': %s.  {{{Originally locked at %s line %d: (%s) '%s'}}}  I will NOT try to relock.\n", #lock, strerror(__res2), __filename, __lineno, __func, __mutex_name); \
+			} \
 		} \
 	} while (0)
 
@@ -313,7 +330,7 @@
 		char __filename[80], __func[80], __mutex_name[80]; \
 		int __lineno; \
 		int __res = ast_find_lock_info(lock, __filename, sizeof(__filename), &__lineno, __func, sizeof(__func), __mutex_name, sizeof(__mutex_name)); \
-		ast_mutex_unlock(lock);
+		int __res2 = ast_mutex_unlock(lock);
 
 /*!
  * \brief Deadlock avoidance lock
@@ -329,9 +346,17 @@
  */
 #define DLA_LOCK(lock) \
 		if (__res < 0) { /* Shouldn't ever happen, but just in case... */ \
-			ast_mutex_lock(lock); \
+			if (__res2) { \
+				ast_log(LOG_WARNING, "Could not unlock mutex '%s': %s and no lock info found!  I will NOT try to relock.\n", #lock, strerror(__res2)); \
+			} else { \
+				ast_mutex_lock(lock); \
+			} \
 		} else { \
-			__ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+			if (__res2) { \
+				ast_log(LOG_WARNING, "Could not unlock mutex '%s': %s.  {{{Originally locked at %s line %d: (%s) '%s'}}}  I will NOT try to relock.\n", #lock, strerror(__res2), __filename, __lineno, __func, __mutex_name); \
+			} else { \
+				__ast_pthread_mutex_lock(__filename, __lineno, __func, __mutex_name, lock); \
+			} \
 		} \
 	} while (0)
 
@@ -1670,9 +1695,15 @@
 	ast_channel_lock(chan);
 
 #define	DEADLOCK_AVOIDANCE(lock) \
-	ast_mutex_unlock(lock); \
-	usleep(1); \
-	ast_mutex_lock(lock);
+	do { \
+		int __res; \
+		if (!(__res = ast_mutex_unlock(lock))) { \
+			usleep(1); \
+			ast_mutex_lock(lock); \
+		} else { \
+			ast_log(LOG_WARNING, "Failed to unlock mutex '%s' (%s).  I will NOT try to relock. {{{ THIS IS A BUG. }}}\n", #lock, strerror(__res)); \
+		} \
+	} while (0)
 
 #define DLA_UNLOCK(lock)	ast_mutex_unlock(lock)
 




More information about the svn-commits mailing list