[asterisk-commits] tilghman: trunk r85176 - in /trunk: ./ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 9 17:21:50 CDT 2007


Author: tilghman
Date: Tue Oct  9 17:21:49 2007
New Revision: 85176

URL: http://svn.digium.com/view/asterisk?view=rev&rev=85176
Log:
Merged revisions 85158 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r85158 | tilghman | 2007-10-09 16:55:06 -0500 (Tue, 09 Oct 2007) | 5 lines

This commit fixes the following issues:
- Deadlock in ast_write (issue #10406)
- Deadlock in ast_read (issue #10406)
- Possible mutex initialization error in lock.h (issue #10571)

........

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/lock.h
    trunk/main/channel.c
    trunk/main/utils.c

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

Modified: trunk/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/lock.h?view=diff&rev=85176&r1=85175&r2=85176
==============================================================================
--- trunk/include/asterisk/lock.h (original)
+++ trunk/include/asterisk/lock.h Tue Oct  9 17:21:49 2007
@@ -149,6 +149,11 @@
 void ast_mark_lock_acquired(void);
 
 /*!
+ * \brief Mark the last lock as failed (trylock)
+ */
+void ast_mark_lock_failed(void);
+
+/*!
  * \brief remove lock info for the current thread
  *
  * this gets called by ast_mutex_unlock so that information on the lock can
@@ -165,6 +170,7 @@
 						const char *mutex_name, ast_mutex_t *t,
 						pthread_mutexattr_t *attr) 
 {
+	int i;
 #ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
 	int canlog = strcmp(filename, "logger.c");
 
@@ -180,10 +186,12 @@
 	}
 #endif
 
-	t->file[0] = filename;
-	t->lineno[0] = lineno;
-	t->func[0] = func;
-	t->thread[0]  = 0;
+	for (i = 0; i < AST_MAX_REENTRANCY; i++) {
+		t->file[i] = NULL;
+		t->lineno[i] = 0;
+		t->func[i] = NULL;
+		t->thread[i]  = 0;
+	}
 	t->reentrancy = 0;
 	t->track = track;
 

Modified: trunk/main/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/main/channel.c?view=diff&rev=85176&r1=85175&r2=85176
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Tue Oct  9 17:21:49 2007
@@ -2110,6 +2110,7 @@
 static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
 {
 	struct ast_frame *f = NULL;	/* the return value */
+	struct ast_channel *base = NULL;
 	int blah;
 	int prestate;
 
@@ -2132,6 +2133,23 @@
 		goto done;
 	}
 	prestate = chan->_state;
+
+	/* Check if there's an underlying channel */
+	if (chan->tech->get_base_channel && (base = chan->tech->get_base_channel(chan)) != chan) {
+		int count = 0;
+		while (!base || ast_mutex_trylock(&base->lock)) {
+			if (count++ > 10) {
+				f = &ast_null_frame;
+				goto done;
+			}
+			ast_mutex_unlock(&chan->lock);
+			usleep(1);
+			ast_mutex_lock(&chan->lock);
+			base = chan->tech->get_base_channel(chan);
+		}
+		ast_mutex_unlock(&chan->lock);
+		chan = base;
+	}
 
 	if (!ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF | AST_FLAG_IN_DTMF) && 
 	    !ast_strlen_zero(chan->dtmfq) && 
@@ -2869,7 +2887,22 @@
 					ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n");
 			}
 		}
-		res = f ? chan->tech->write(chan, f) : 0;
+
+		if (f) {
+			struct ast_channel *base = NULL;
+			if (!chan->tech->get_base_channel || chan == chan->tech->get_base_channel(chan))
+				res = chan->tech->write(chan, f);
+			else {
+				while (chan->tech->get_base_channel && (((base = chan->tech->get_base_channel(chan)) && ast_mutex_trylock(&base->lock)) || base == NULL)) {
+					ast_mutex_unlock(&chan->lock);
+					usleep(1);
+					ast_mutex_lock(&chan->lock);
+				}
+				res = base->tech->write(base, f);
+				ast_mutex_unlock(&base->lock);
+			}
+		} else
+			res = 0;
 		break;
 	case AST_FRAME_NULL:
 	case AST_FRAME_IAX:

Modified: trunk/main/utils.c
URL: http://svn.digium.com/view/asterisk/trunk/main/utils.c?view=diff&rev=85176&r1=85175&r2=85176
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Tue Oct  9 17:21:49 2007
@@ -549,7 +549,7 @@
 		int times_locked;
 		enum ast_lock_type type;
 		/*! This thread is waiting on this lock */
-		unsigned int pending:1;
+		int pending:2;
 	} locks[AST_MAX_LOCKS];
 	/*! This is the number of locks currently held by this thread.
 	 *  The index (num_locks - 1) has the info on the last one in the
@@ -645,6 +645,19 @@
 	pthread_mutex_unlock(&lock_info->lock);
 }
 
+void ast_mark_lock_failed(void)
+{
+	struct thr_lock_info *lock_info;
+
+	if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
+		return;
+
+	pthread_mutex_lock(&lock_info->lock);
+	lock_info->locks[lock_info->num_locks - 1].pending = -1;
+	lock_info->locks[lock_info->num_locks - 1].times_locked--;
+	pthread_mutex_unlock(&lock_info->lock);
+}
+
 void ast_remove_lock_info(void *lock_addr)
 {
 	struct thr_lock_info *lock_info;
@@ -730,7 +743,7 @@
 		pthread_mutex_lock(&lock_info->lock);
 		for (i = 0; i < lock_info->num_locks; i++) {
 			ast_cli(a->fd, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n", 
-				lock_info->locks[i].pending ? "Waiting for " : "", i,
+				lock_info->locks[i].pending > 0 ? "Waiting for " : lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
 				lock_info->locks[i].file, 
 				locktype2str(lock_info->locks[i].type),
 				lock_info->locks[i].line_num,




More information about the asterisk-commits mailing list