[asterisk-commits] murf: branch murf/mtxprof4 r132240 - in /team/murf/mtxprof4: ./ build_tools/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 18 16:33:29 CDT 2008


Author: murf
Date: Fri Jul 18 16:33:29 2008
New Revision: 132240

URL: http://svn.digium.com/view/asterisk?view=rev&rev=132240
Log:
Checkpoint. Calls can thru, but sipp is getting unexpected Proxy Authentication Required... looks like my sip.conf needs a tweak

Modified:
    team/murf/mtxprof4/Makefile
    team/murf/mtxprof4/build_tools/cflags-devmode.xml
    team/murf/mtxprof4/channels/chan_agent.c
    team/murf/mtxprof4/channels/chan_dahdi.c
    team/murf/mtxprof4/channels/chan_iax2.c
    team/murf/mtxprof4/channels/chan_local.c
    team/murf/mtxprof4/channels/chan_mgcp.c
    team/murf/mtxprof4/channels/chan_phone.c
    team/murf/mtxprof4/channels/chan_sip.c
    team/murf/mtxprof4/include/asterisk.h
    team/murf/mtxprof4/include/asterisk/linkedlists.h
    team/murf/mtxprof4/include/asterisk/lock.h
    team/murf/mtxprof4/include/asterisk/time.h
    team/murf/mtxprof4/main/app.c
    team/murf/mtxprof4/main/asterisk.c
    team/murf/mtxprof4/main/astobj2.c
    team/murf/mtxprof4/main/channel.c
    team/murf/mtxprof4/main/dnsmgr.c
    team/murf/mtxprof4/main/file.c
    team/murf/mtxprof4/main/loader.c
    team/murf/mtxprof4/main/pbx.c
    team/murf/mtxprof4/main/rtp.c
    team/murf/mtxprof4/main/udptl.c
    team/murf/mtxprof4/main/utils.c
    team/murf/mtxprof4/pbx/pbx_config.c
    team/murf/mtxprof4/res/res_agi.c
    team/murf/mtxprof4/res/res_monitor.c
    team/murf/mtxprof4/res/res_smdi.c
    team/murf/mtxprof4/utils/ael_main.c

Modified: team/murf/mtxprof4/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/Makefile?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/Makefile (original)
+++ team/murf/mtxprof4/Makefile Fri Jul 18 16:33:29 2008
@@ -96,6 +96,7 @@
 
 # Include debug and macro symbols in the executables (-g) and profiling info (-pg)
 DEBUG=-g3
+#ASTLDFLAGS += -pg
 
 # Staging directory
 # Files are copied here temporarily during the install process

Modified: team/murf/mtxprof4/build_tools/cflags-devmode.xml
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/build_tools/cflags-devmode.xml?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/build_tools/cflags-devmode.xml (original)
+++ team/murf/mtxprof4/build_tools/cflags-devmode.xml Fri Jul 18 16:33:29 2008
@@ -11,6 +11,8 @@
 		<member name="DUMP_SCHEDULER" displayname="Dump Scheduler Contents for Debugging">
 		</member>
 		<member name="MTX_PROFILE" displayname="Enable Code Profiling Using TSC Counters">
+			
+			<conflict>DETECT_DEADLOCKS</conflict>
 		</member>
 		<member name="TRACE_FRAMES" displayname="Trace Frame Allocations">
 		</member>

Modified: team/murf/mtxprof4/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/channels/chan_agent.c?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/channels/chan_agent.c (original)
+++ team/murf/mtxprof4/channels/chan_agent.c Fri Jul 18 16:33:29 2008
@@ -291,7 +291,8 @@
 
 	/* Try to be safe, but don't deadlock */
 	for (i = 0; i < 10; i++) {
-		if ((res = AST_LIST_TRYLOCK(&agents)) == 0) {
+		AST_LIST_TRYLOCK_ASSIGN(&agents,res);
+		if (res == 0) {
 			break;
 		}
 	}
@@ -1014,6 +1015,7 @@
 static struct ast_channel *agent_new(struct agent_pvt *p, int state)
 {
 	struct ast_channel *tmp;
+	int ret5;
 #if 0
 	if (!p->chan) {
 		ast_log(LOG_WARNING, "No channel? :(\n");
@@ -1064,7 +1066,9 @@
 	 * implemented in the kernel for this.
 	 */
 	p->app_sleep_cond = 0;
-	if(ast_strlen_zero(p->loginchan) && ast_mutex_trylock(&p->app_lock)) {
+	if (ast_strlen_zero(p->loginchan))
+		ast_mutex_trylock_assign(&p->app_lock, ret5);
+	if(ast_strlen_zero(p->loginchan) && ret5) {
 		if (p->chan) {
 			ast_queue_frame(p->chan, &ast_null_frame);
 			ast_mutex_unlock(&p->lock);	/* For other thread to read the condition. */
@@ -1637,7 +1641,10 @@
 				if (!soft) {
 					ast_mutex_lock(&p->lock);
 
-					while (p->owner && ast_channel_trylock(p->owner)) {
+					while (p->owner) {
+						int ret;
+						ast_channel_trylock_assign(p->owner,ret);
+						if (!ret) break;
 						DEADLOCK_AVOIDANCE(&p->lock);
 					}
 					if (p->owner) {
@@ -1645,7 +1652,10 @@
 						ast_channel_unlock(p->owner);
 					}
 
-					while (p->chan && ast_channel_trylock(p->chan)) {
+					while (p->chan) {
+						int ret;
+						ast_channel_trylock_assign(p->owner,ret);
+						if (!ret) break;
 						DEADLOCK_AVOIDANCE(&p->lock);
 					}
 					if (p->chan) {

Modified: team/murf/mtxprof4/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/channels/chan_dahdi.c?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/channels/chan_dahdi.c (original)
+++ team/murf/mtxprof4/channels/chan_dahdi.c Fri Jul 18 16:33:29 2008
@@ -740,7 +740,7 @@
 	int res;
 	/* Grab the lock first */
 	do {
-		res = ast_mutex_trylock(&pri->lock);
+		ast_mutex_trylock_assign(&pri->lock, res);
 		if (res) {
 			DEADLOCK_AVOIDANCE(&pvt->lock);
 		}
@@ -802,13 +802,17 @@
 static void wakeup_sub(struct dahdi_pvt *p, int a, void *pri)
 #endif
 {
+	int lockret;
 #ifdef HAVE_PRI
-	if (pri)
+	if (pri) {
 		ast_mutex_unlock(&pri->lock);
+	}
+
 #endif			
 	for (;;) {
 		if (p->subs[a].owner) {
-			if (ast_mutex_trylock(&p->subs[a].owner->lock)) {
+			ast_mutex_trylock_assign(&p->subs[a].owner->lock, lockret);
+			if (lockret) {
 				DEADLOCK_AVOIDANCE(&p->lock);
 			} else {
 				ast_queue_frame(p->subs[a].owner, &ast_null_frame);
@@ -831,13 +835,16 @@
 #endif
 {
 	/* We must unlock the PRI to avoid the possibility of a deadlock */
+	int lockret;
 #ifdef HAVE_PRI
-	if (pri)
+	if (pri) {
 		ast_mutex_unlock(&pri->lock);
+	}
 #endif		
 	for (;;) {
 		if (p->owner) {
-			if (ast_mutex_trylock(&p->owner->lock)) {
+			ast_mutex_trylock_assign(&p->owner->lock, lockret);
+			if (lockret) {
 				DEADLOCK_AVOIDANCE(&p->lock);
 			} else {
 				ast_queue_frame(p->owner, f);
@@ -848,8 +855,9 @@
 			break;
 	}
 #ifdef HAVE_PRI
-	if (pri)
+	if (pri) {
 		ast_mutex_lock(&pri->lock);
+	}
 #endif		
 }
 
@@ -3063,8 +3071,11 @@
 	if (needlock) {
 		ast_mutex_lock(&master->lock);
 		if (slave) {
-			while (ast_mutex_trylock(&slave->lock)) {
+			int tlock;
+			ast_mutex_trylock_assign(&slave->lock, tlock);
+			while (tlock) {
 				DEADLOCK_AVOIDANCE(&master->lock);
+				ast_mutex_trylock_assign(&slave->lock, tlock);
 			}
 		}
 	}
@@ -3103,8 +3114,9 @@
 	}
 	update_conf(master);
 	if (needlock) {
-		if (slave)
+		if (slave) {
 			ast_mutex_unlock(&slave->lock);
+		}
 		ast_mutex_unlock(&master->lock);
 	}
 }
@@ -3185,6 +3197,7 @@
 	int priority = 0;
 	struct ast_channel *oc0, *oc1;
 	enum ast_bridge_result res;
+	int lockret;
 
 #ifdef PRI_2BCT
 	int triedtopribridge = 0;
@@ -3200,8 +3213,10 @@
 		return AST_BRIDGE_FAILED_NOWARN;
 
 	ast_mutex_lock(&c0->lock);
-	while (ast_mutex_trylock(&c1->lock)) {
+	ast_mutex_trylock_assign(&c1->lock, lockret);
+	while (lockret) {
 		DEADLOCK_AVOIDANCE(&c0->lock);
+		ast_mutex_trylock_assign(&c1->lock, lockret);
 	}
 
 	p0 = c0->tech_pvt;
@@ -3228,14 +3243,16 @@
 	oc0 = p0->owner;
 	oc1 = p1->owner;
 
-	if (ast_mutex_trylock(&p0->lock)) {
+	ast_mutex_trylock_assign(&p0->lock, lockret);
+	if (lockret) {
 		/* Don't block, due to potential for deadlock */
 		ast_mutex_unlock(&c0->lock);
 		ast_mutex_unlock(&c1->lock);
 		ast_log(LOG_NOTICE, "Avoiding deadlock...\n");
 		return AST_BRIDGE_RETRY;
 	}
-	if (ast_mutex_trylock(&p1->lock)) {
+	ast_mutex_trylock_assign(&p1->lock,lockret);
+	if (lockret) {
 		/* Don't block, due to potential for deadlock */
 		ast_mutex_unlock(&p0->lock);
 		ast_mutex_unlock(&c0->lock);
@@ -3370,8 +3387,10 @@
 		/* Here's our main loop...  Start by locking things, looking for private parts, 
 		   and then balking if anything is wrong */
 		ast_mutex_lock(&c0->lock);
-		while (ast_mutex_trylock(&c1->lock)) {
+		ast_mutex_trylock_assign(&c1->lock,lockret);
+		while (lockret) {
 			DEADLOCK_AVOIDANCE(&c0->lock);
+			ast_mutex_trylock_assign(&c1->lock,lockret);
 		}
 
 		p0 = c0->tech_pvt;
@@ -3687,6 +3706,7 @@
 	pthread_attr_t attr;
 	struct ast_channel *chan;
 	struct ast_frame *f;
+	int lockret;
 
 	index = dahdi_get_index(ast, p, 0);
 	mysig = p->sig;
@@ -3903,17 +3923,22 @@
 						unsigned int mssinceflash;
 						/* Here we have to retain the lock on both the main channel, the 3-way channel, and
 						   the private structure -- not especially easy or clean */
-						while (p->subs[SUB_THREEWAY].owner && ast_mutex_trylock(&p->subs[SUB_THREEWAY].owner->lock)) {
-							/* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
-							ast_mutex_unlock(&p->lock);
-							DEADLOCK_AVOIDANCE(&ast->lock);
-							/* 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_mutex_lock(&p->lock);
-							if (p->owner != ast) {
-								ast_log(LOG_WARNING, "This isn't good...\n");
-								return NULL;
+						if (p->subs[SUB_THREEWAY].owner) {
+							
+							ast_mutex_trylock_assign(&p->subs[SUB_THREEWAY].owner->lock,lockret);
+							while (p->subs[SUB_THREEWAY].owner && lockret) {
+								/* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
+								ast_mutex_unlock(&p->lock);
+								DEADLOCK_AVOIDANCE(&ast->lock);
+								/* 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_mutex_lock(&p->lock);
+								if (p->owner != ast) {
+									ast_log(LOG_WARNING, "This isn't good...\n");
+									return NULL;
+								}
+								ast_channel_trylock_assign(p->subs[SUB_THREEWAY].owner,lockret);
 							}
 						}
 						if (!p->subs[SUB_THREEWAY].owner) {
@@ -3946,19 +3971,22 @@
 								} else {
 									if ((res = attempt_transfer(p)) < 0) {
 										p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
-										if (p->subs[SUB_THREEWAY].owner)
+										if (p->subs[SUB_THREEWAY].owner) {
 											ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
+										}
 									} else if (res) {
 										/* Don't actually hang up at this point */
-										if (p->subs[SUB_THREEWAY].owner)
+										if (p->subs[SUB_THREEWAY].owner) {
 											ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
+										}
 										break;
 									}
 								}
 							} else {
 								p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
-								if (p->subs[SUB_THREEWAY].owner)
+								if (p->subs[SUB_THREEWAY].owner) {
 									ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
+								}
 							}
 						} else {
 							ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
@@ -4659,9 +4687,12 @@
 	int index;
 	void *readbuf;
 	struct ast_frame *f;
-
-	while (ast_mutex_trylock(&p->lock)) {
+	int lockret;
+
+	ast_mutex_trylock_assign(&p->lock,lockret);
+	while (lockret) {
 		DEADLOCK_AVOIDANCE(&ast->lock);
+		ast_mutex_trylock_assign(&p->lock,lockret);
 	}
 
 	index = dahdi_get_index(ast, p, 0);
@@ -8332,15 +8363,22 @@
 {
 	int x;
 	int redo;
+	int lockret;
+	
 	ast_mutex_unlock(&pri->lock);
 	ast_mutex_lock(&p->lock);
 	do {
 		redo = 0;
 		for (x = 0; x < 3; x++) {
-			while (p->subs[x].owner && ast_mutex_trylock(&p->subs[x].owner->lock)) {
-				redo++;
-				DEADLOCK_AVOIDANCE(&p->lock);
-			}
+			if (p->subs[x].owner) {
+				ast_mutex_trylock_assign(&p->subs[x].owner->lock, lockret);
+				while (p->subs[x].owner && lockret) {
+					redo++;
+					DEADLOCK_AVOIDANCE(&p->lock);
+					ast_mutex_trylock_assign(&p->subs[x].owner->lock, lockret);
+				}
+			}
+			
 			if (p->subs[x].owner) {
 				ast_queue_hangup(p->subs[x].owner);
 				ast_mutex_unlock(&p->subs[x].owner->lock);
@@ -8789,8 +8827,9 @@
 							chanpos = -1;
 						}
 					}
-					if (chanpos > -1)
+					if (chanpos > -1) {
 						ast_mutex_unlock(&pri->pvts[chanpos]->lock);
+					}
 				}
 				if ((chanpos < 0) && (e->ring.flexible))
 					chanpos = pri_find_empty_chan(pri, 1);
@@ -8799,8 +8838,9 @@
 					if (pri->switchtype == PRI_SWITCH_GR303_TMC) {
 						/* Should be safe to lock CRV AFAIK while bearer is still locked */
 						crv = pri_find_crv(pri, pri_get_crv(pri->pri, e->ring.call, NULL));
-						if (crv)
+						if (crv) {
 							ast_mutex_lock(&crv->lock);
+						}
 						if (!crv || crv->owner) {
 							pri->pvts[chanpos]->call = NULL;
 							if (crv) {
@@ -8810,8 +8850,9 @@
 							} else
 								ast_log(LOG_NOTICE, "Call received for unconfigured CRV %d on span %d\n", pri_get_crv(pri->pri, e->ring.call, NULL), pri->span);
 							pri_hangup(pri->pri, e->ring.call, PRI_CAUSE_INVALID_CALL_REFERENCE);
-							if (crv)
+							if (crv) {
 								ast_mutex_unlock(&crv->lock);
+							}
 							ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 							break;
 						}
@@ -9011,8 +9052,9 @@
 						pri->pvts[chanpos]->call = NULL;
 						pri->pvts[chanpos]->exten[0] = '\0';
 					}
-					if (crv)
+					if (crv) {
 						ast_mutex_unlock(&crv->lock);
+					}
 					ast_mutex_unlock(&pri->pvts[chanpos]->lock);
 				} else {
 					if (e->ring.flexible)

Modified: team/murf/mtxprof4/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/channels/chan_iax2.c?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/channels/chan_iax2.c (original)
+++ team/murf/mtxprof4/channels/chan_iax2.c Fri Jul 18 16:33:29 2008
@@ -1298,7 +1298,10 @@
 	owner = pvt ? pvt->owner : NULL;
 
 	if (owner) {
-		if (ast_mutex_trylock(&owner->lock)) {
+		int lockret;
+		
+		ast_mutex_trylock_assign(&owner->lock,lockret);
+		if (lockret) {
 			if (option_debug > 2)
 				ast_log(LOG_DEBUG, "Avoiding IAX destroy deadlock\n");
 			DEADLOCK_AVOIDANCE(&iaxsl[callno]);
@@ -1501,11 +1504,13 @@
 			iaxs[callno] = NULL;
 			iaxs[x]->pingid = iax2_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
 			iaxs[x]->lagid = iax2_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
-			if (locked)
+			if (locked) {
 				ast_mutex_unlock(&iaxsl[callno]);
+			}
 			res = x;
-			if (!locked)
+			if (!locked) {
 				ast_mutex_unlock(&iaxsl[x]);
+			}
 			break;
 		}
 		ast_mutex_unlock(&iaxsl[x]);
@@ -1584,8 +1589,9 @@
 					res = x;
 				}
 			}
-			if (!res || !return_locked)
+			if (!res || !return_locked) {
 				ast_mutex_unlock(&iaxsl[x]);
+			}
 		}
 
 		for (x = TRUNK_CALL_START; !res && x < maxtrunkcall; x++) {
@@ -1596,8 +1602,9 @@
 					res = x;
 				}
 			}
-			if (!res || !return_locked)
+			if (!res || !return_locked) {
 				ast_mutex_unlock(&iaxsl[x]);
+			}
 		}
 
 		if (res) {
@@ -1672,8 +1679,9 @@
 			ast_mutex_unlock(&iaxsl[x]);
 			return 0;
 		}
-		if (!return_locked)
+		if (!return_locked) {
 			ast_mutex_unlock(&iaxsl[x]);
+		}
 		res = x;
 	}
 	return res;
@@ -1703,7 +1711,10 @@
 {
 	for (;;) {
 		if (iaxs[callno] && iaxs[callno]->owner) {
-			if (ast_mutex_trylock(&iaxs[callno]->owner->lock)) {
+			int lockret;
+			
+			ast_mutex_trylock_assign(&iaxs[callno]->owner->lock,lockret);
+			if (lockret) {
 				/* Avoid deadlock by pausing and trying again */
 				DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			} else {
@@ -1734,7 +1745,10 @@
 {
 	for (;;) {
 		if (iaxs[callno] && iaxs[callno]->owner) {
-			if (ast_mutex_trylock(&iaxs[callno]->owner->lock)) {
+			int lockret;
+			
+			ast_mutex_trylock_assign(&iaxs[callno]->owner->lock,lockret);
+			if (lockret) {
 				/* Avoid deadlock by pausing and trying again */
 				DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			} else {
@@ -1766,7 +1780,9 @@
 {
 	for (;;) {
 		if (iaxs[callno] && iaxs[callno]->owner) {
-			if (ast_mutex_trylock(&iaxs[callno]->owner->lock)) {
+			int lockret;
+			ast_mutex_trylock_assign(&iaxs[callno]->owner->lock,lockret);
+			if (lockret) {
 				/* Avoid deadlock by pausing and trying again */
 				DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			} else {
@@ -2251,8 +2267,9 @@
 		f->retries = -1;
 		freeme++;
 	}
-	if (callno)
+	if (callno) {
 		ast_mutex_unlock(&iaxsl[callno]);
+	}
 	/* Do not try again */
 	if (freeme) {
 		/* Don't attempt delivery, just remove it from the queue */
@@ -3505,9 +3522,13 @@
 
 static void lock_both(unsigned short callno0, unsigned short callno1)
 {
+	int tlock;
+	
 	ast_mutex_lock(&iaxsl[callno0]);
-	while (ast_mutex_trylock(&iaxsl[callno1])) {
+	ast_mutex_trylock_assign(&iaxsl[callno1],tlock);
+	while (tlock) {
 		DEADLOCK_AVOIDANCE(&iaxsl[callno0]);
+		ast_mutex_trylock_assign(&iaxsl[callno1],tlock);
 	}
 }
 
@@ -6683,8 +6704,9 @@
 		iax_ie_append_short(&ied1, IAX_IE_REFRESH, iaxdefaultdpcache);
 		send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_DPREP, 0, ied1.buf, ied1.pos, -1);
 	}
-	if (!skiplock)
+	if (!skiplock) {
 		ast_mutex_unlock(&iaxsl[callno]);
+	}
 }
 
 static void *dp_lookup_thread(void *data)
@@ -7228,8 +7250,9 @@
 				raw_hangup(&sin, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS, ntohs(mh->callno) & ~IAX_FLAG_FULL,
 				fd);
 		}
-		if (fr->callno > 0) 
+		if (fr->callno > 0) {
 			ast_mutex_unlock(&iaxsl[fr->callno]);
+		}
 		return 1;
 	}
 	if (ast_test_flag(iaxs[fr->callno], IAX_ENCRYPTED)) {
@@ -7452,8 +7475,10 @@
 						ast_log(LOG_DEBUG, "Ooh, voice format changed to %d\n", f.subclass);
 					if (iaxs[fr->callno]->owner) {
 						int orignative;
+						int lockret;
 retryowner:
-						if (ast_mutex_trylock(&iaxs[fr->callno]->owner->lock)) {
+						ast_mutex_trylock_assign(&iaxs[fr->callno]->owner->lock,lockret);
+						if (lockret) {
 							DEADLOCK_AVOIDANCE(&iaxsl[fr->callno]);
 							if (iaxs[fr->callno] && iaxs[fr->callno]->owner) goto retryowner;
 						}
@@ -7884,12 +7909,15 @@
 				} else {
 					ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED);
 					if (iaxs[fr->callno]->owner) {
+						int lockret;
+						
 						/* Switch us to use a compatible format */
 						iaxs[fr->callno]->owner->nativeformats = iaxs[fr->callno]->peerformat;
 						if (option_verbose > 2)
 							ast_verbose(VERBOSE_PREFIX_3 "Format for call is %s\n", ast_getformatname(iaxs[fr->callno]->owner->nativeformats));
 retryowner2:
-						if (ast_mutex_trylock(&iaxs[fr->callno]->owner->lock)) {
+						ast_mutex_trylock_assign(&iaxs[fr->callno]->owner->lock,lockret);
+						if (lockret) {
 							DEADLOCK_AVOIDANCE(&iaxsl[fr->callno]);
 							if (iaxs[fr->callno] && iaxs[fr->callno]->owner) goto retryowner2;
 						}
@@ -8917,8 +8945,9 @@
 		iax2_destroy(callno);
 		ast_mutex_unlock(&iaxsl[callno]);
 	}
-	if (heldcall)
+	if (heldcall) {
 		ast_mutex_unlock(&iaxsl[heldcall]);
+	}
 	callno = peer->callno = find_callno(0, 0, &peer->addr, NEW_FORCE, peer->sockfd, 0);
 	if (heldcall)
 		ast_mutex_lock(&iaxsl[heldcall]);
@@ -9095,11 +9124,14 @@
 		count = 0;
 		wakeup = -1;
 		AST_LIST_TRAVERSE_SAFE_BEGIN(&iaxq.queue, f, list) {
+			int lockret;
+			
 			if (f->sentyet)
 				continue;
 			
 			/* Try to lock the pvt, if we can't... don't fret - defer it till later */
-			if (ast_mutex_trylock(&iaxsl[f->callno])) {
+			ast_mutex_trylock_assign(&iaxsl[f->callno],lockret);
+			if (lockret) {
 				wakeup = 1;
 				continue;
 			}
@@ -10292,9 +10324,11 @@
 	char *tmpstr;
 
 	for (x = 0; x < ARRAY_LEN(iaxs); x++) {
+		int tlock;
 		/* Look for an *exact match* call.  Once a call is negotiated, it can only
 		   look up entries for a single context */
-		if (!ast_mutex_trylock(&iaxsl[x])) {
+		ast_mutex_trylock_assign(&iaxsl[x],tlock);
+		if (!tlock) {
 			if (iaxs[x] && !strcasecmp(data, iaxs[x]->dproot))
 				return x;
 			ast_mutex_unlock(&iaxsl[x]);

Modified: team/murf/mtxprof4/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/channels/chan_local.c?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/channels/chan_local.c (original)
+++ team/murf/mtxprof4/channels/chan_local.c Fri Jul 18 16:33:29 2008
@@ -164,7 +164,8 @@
 	struct ast_channel *us, int us_locked)
 {
 	struct ast_channel *other = NULL;
-
+	int lockret;
+	
 	/* Recalculate outbound channel */
 	other = isoutbound ? p->owner : p->chan;
 
@@ -183,19 +184,26 @@
 	}
 
 	/* Ensure that we have both channels locked */
-	while (other && ast_channel_trylock(other)) {
+	if (other) {
+		ast_channel_trylock_assign(other,lockret);
+	}
+ 	while (other && lockret) {
+ 		int tlock;
 		ast_mutex_unlock(&p->lock);
 		if (us && us_locked) {
 			do {
 				ast_channel_unlock(us);
 				usleep(1);
 				ast_channel_lock(us);
-			} while (ast_mutex_trylock(&p->lock));
+ 				ast_mutex_trylock_assign(&p->lock,tlock);
+ 			} while (tlock);
 		} else {
 			usleep(1);
 			ast_mutex_lock(&p->lock);
 		}
 		other = isoutbound ? p->owner : p->chan;
+		if (other)
+			ast_channel_trylock_assign(other,lockret);
 	}
 
 	if (other) {
@@ -225,8 +233,10 @@
 		res = local_queue_frame(p, isoutbound, &answer, ast, 1);
 	} else
 		ast_log(LOG_WARNING, "Huh?  Local is being asked to answer?\n");
-	if (!res)
-		ast_mutex_unlock(&p->lock);
+	if (!res) {
+		ast_mutex_unlock(&p->lock);
+	}
+	
 	return res;
 }
 
@@ -242,13 +252,16 @@
 	   outbound channel during the masquerade)
 	*/
 	if (isoutbound && p->chan->_bridge /* Not ast_bridged_channel!  Only go one step! */ && AST_LIST_EMPTY(&p->owner->readq)) {
+		int lockret;
 		/* Masquerade bridged channel into owner */
 		/* Lock everything we need, one by one, and give up if
 		   we can't get everything.  Remember, we'll get another
 		   chance in just a little bit */
-		if (!ast_mutex_trylock(&(p->chan->_bridge)->lock)) {
+ 		ast_mutex_trylock_assign(&(p->chan->_bridge)->lock,lockret);
+ 		if (!lockret) {
 			if (!p->chan->_bridge->_softhangup) {
-				if (!ast_mutex_trylock(&p->owner->lock)) {
+				ast_mutex_trylock_assign(&p->owner->lock,lockret);
+				if (!lockret) {
 					if (!p->owner->_softhangup) {
 						if(p->owner->monitor && !p->chan->_bridge->monitor) {
 							/* If a local channel is being monitored, we don't want a masquerade
@@ -275,9 +288,12 @@
 #if 0
 	} else if (!isoutbound && p->owner && p->owner->_bridge && p->chan && AST_LIST_EMPTY(&p->chan->readq)) {
 		/* Masquerade bridged channel into chan */
-		if (!ast_mutex_trylock(&(p->owner->_bridge)->lock)) {
+		int lockret;
+		ast_mutex_trylock_assign(&(p->owner->_bridge)->lock,lockret);
+		if (!lockret) {
 			if (!p->owner->_bridge->_softhangup) {
-				if (!ast_mutex_trylock(&p->chan->lock)) {
+				ast_mutex_trylock_assign(&p->chan->lock,lockret);
+				if (!lockret) {
 					if (!p->chan->_softhangup) {
 						ast_channel_masquerade(p->chan, p->owner->_bridge);
 						ast_set_flag(p, LOCAL_ALREADY_MASQED);
@@ -317,8 +333,9 @@
 			ast_log(LOG_DEBUG, "Not posting to queue since already masked on '%s'\n", ast->name);
 		res = 0;
 	}
-	if (!res)
-		ast_mutex_unlock(&p->lock);
+	if (!res) {
+		ast_mutex_unlock(&p->lock);
+	}
 	return res;
 }
 
@@ -366,8 +383,9 @@
 		f.subclass = condition;
 		f.data = (void*)data;
 		f.datalen = datalen;
-		if (!(res = local_queue_frame(p, isoutbound, &f, ast, 1)))
+		if (!(res = local_queue_frame(p, isoutbound, &f, ast, 1))) {
 			ast_mutex_unlock(&p->lock);
+		}
 	}
 
 	return res;
@@ -386,8 +404,9 @@
 	ast_mutex_lock(&p->lock);
 	isoutbound = IS_OUTBOUND(ast, p);
 	f.subclass = digit;
-	if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
-		ast_mutex_unlock(&p->lock);
+	if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0))) {
+		ast_mutex_unlock(&p->lock);
+	}
 
 	return res;
 }
@@ -406,8 +425,9 @@
 	isoutbound = IS_OUTBOUND(ast, p);
 	f.subclass = digit;
 	f.len = duration;
-	if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
-		ast_mutex_unlock(&p->lock);
+	if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0))) {
+		ast_mutex_unlock(&p->lock);
+	}
 
 	return res;
 }
@@ -426,8 +446,9 @@
 	isoutbound = IS_OUTBOUND(ast, p);
 	f.data = (char *) text;
 	f.datalen = strlen(text) + 1;
-	if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
-		ast_mutex_unlock(&p->lock);
+	if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0))) {
+		ast_mutex_unlock(&p->lock);
+	}
 	return res;
 }
 
@@ -446,8 +467,9 @@
 	f.subclass = subclass;
 	f.data = (char *)data;
 	f.datalen = datalen;
-	if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
-		ast_mutex_unlock(&p->lock);
+	if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0))) {
+		ast_mutex_unlock(&p->lock);
+	}
 	return res;
 }
 
@@ -508,22 +530,27 @@
 	struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP };
 	struct ast_channel *ochan = NULL;
 	int glaredetect = 0, res = 0;
-
-	if (!p)
-		return -1;
-
-	while (ast_mutex_trylock(&p->lock)) {
+	int lockret;
+
+	if (!p)
+		return -1;
+
+	ast_mutex_trylock_assign(&p->lock,lockret);
+	while (lockret) {
 		ast_channel_unlock(ast);
 		usleep(1);
 		ast_channel_lock(ast);
+		ast_mutex_trylock_assign(&p->lock,lockret);
 	}
 
 	isoutbound = IS_OUTBOUND(ast, p);
 	if (isoutbound) {
 		const char *status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS");
 		if ((status) && (p->owner)) {
+			int lockret;
 			/* Deadlock avoidance */
-			while (p->owner && ast_channel_trylock(p->owner)) {
+			ast_channel_trylock_assign(p->owner,lockret);
+			while (p->owner && lockret) {
 				ast_mutex_unlock(&p->lock);
 				if (ast) {
 					ast_channel_unlock(ast);
@@ -533,6 +560,7 @@
 					ast_channel_lock(ast);
 				}
 				ast_mutex_lock(&p->lock);
+				ast_channel_trylock_assign(p->owner,lockret);
 			}
 			if (p->owner) {
 				pbx_builtin_setvar_helper(p->owner, "CHANLOCALSTATUS", status);
@@ -578,8 +606,9 @@
 		ochan = p->chan;
 	else
 		res = local_queue_frame(p, isoutbound, &f, NULL, 1);
-	if (!res)
-		ast_mutex_unlock(&p->lock);
+	if (!res) {
+		ast_mutex_unlock(&p->lock);
+	}
 	if (ochan)
 		ast_hangup(ochan);
 	return 0;
@@ -755,11 +784,13 @@
 static int unload_module(void)
 {
 	struct local_pvt *p = NULL;
-
+	int lockret;
+	
 	/* First, take us out of the channel loop */
 	ast_cli_unregister_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
 	ast_channel_unregister(&local_tech);
-	if (!AST_LIST_LOCK(&locals)) {
+	AST_LIST_LOCK_ASSIGN(&locals,lockret);
+	if (!lockret) {
 		/* Hangup all interfaces if they have an owner */
 		AST_LIST_TRAVERSE(&locals, p, list) {
 			if (p->owner)

Modified: team/murf/mtxprof4/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/channels/chan_mgcp.c?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/channels/chan_mgcp.c (original)
+++ team/murf/mtxprof4/channels/chan_mgcp.c Fri Jul 18 16:33:29 2008
@@ -569,7 +569,9 @@
 {
 	for(;;) {
 		if (sub->owner) {
-			if (!ast_mutex_trylock(&sub->owner->lock)) {
+			int lockret;
+			ast_mutex_trylock_assign(&sub->owner->lock,lockret);
+			if (!lockret) {
 				ast_queue_frame(sub->owner, f);
 				ast_mutex_unlock(&sub->owner->lock);
 				break;
@@ -585,7 +587,9 @@
 {
 	for(;;) {
 		if (sub->owner) {
-			if (!ast_mutex_trylock(&sub->owner->lock)) {
+			int lockret;
+			ast_mutex_trylock_assign(&sub->owner->lock,lockret);
+			if (!lockret) {
 				ast_queue_hangup(sub->owner);
 				ast_mutex_unlock(&sub->owner->lock);
 				break;
@@ -3523,10 +3527,13 @@
 
 static int restart_monitor(void)
 {
+	int lockret;
+	
 	/* If we're supposed to be stopped -- stay stopped */
 	if (monitor_thread == AST_PTHREADT_STOP)
 		return 0;
-	if (ast_mutex_lock(&monlock)) {
+	ast_mutex_lock_assign(&monlock, lockret);
+	if (lockret) {
 		ast_log(LOG_WARNING, "Unable to lock monitor\n");
 		return -1;
 	}
@@ -4364,9 +4371,12 @@
 {
 	struct mgcp_endpoint *e;
 	struct mgcp_gateway *g;
-
+	int lockret;
+	int tlock;
+	
 	/* Check to see if we're reloading */
-	if (ast_mutex_trylock(&mgcp_reload_lock)) {
+	ast_mutex_trylock_assign(&mgcp_reload_lock,tlock);
+	if (tlock) {
 		ast_log(LOG_WARNING, "MGCP is currently reloading.  Unable to remove module.\n");
 		return -1;
 	} else {
@@ -4378,7 +4388,8 @@
 	ast_channel_unregister(&mgcp_tech);
 
 	/* Shut down the monitoring thread */
-	if (!ast_mutex_lock(&monlock)) {
+	ast_mutex_lock_assign(&monlock, lockret);
+	if (!lockret) {
 		if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
 			pthread_cancel(monitor_thread);
 			pthread_kill(monitor_thread, SIGURG);
@@ -4394,8 +4405,9 @@
 		mgcp_reload(0, 0, NULL);
 		return -1;
 	}
-
-	if (!ast_mutex_lock(&gatelock)) {
+	
+	ast_mutex_lock_assign(&gatelock, lockret);
+	if (!lockret) {
 		for (g = gateways; g; g = g->next) {
 			g->delme = 1;
 			for (e = g->endpoints; e; e = e->next)

Modified: team/murf/mtxprof4/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/channels/chan_phone.c?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/channels/chan_phone.c (original)
+++ team/murf/mtxprof4/channels/chan_phone.c Fri Jul 18 16:33:29 2008
@@ -1007,10 +1007,12 @@
 	/* This thread monitors all the frame relay interfaces which are not yet in use
 	   (and thus do not have a separate thread) indefinitely */
 	while (monitor) {
+		int lockret;
 		/* Don't let anybody kill us right away.  Nobody should lock the interface list
 		   and wait for the monitor list, but the other way around is okay. */
 		/* Lock the interface list */
-		if (ast_mutex_lock(&iflock)) {
+		ast_mutex_lock_assign(&iflock, lockret);
+		if (lockret) {
 			ast_log(LOG_ERROR, "Unable to grab interface lock\n");
 			return NULL;
 		}
@@ -1073,7 +1075,8 @@
 			continue;
 		/* Alright, lock the interface list again, and let's look and see what has
 		   happened */
-		if (ast_mutex_lock(&iflock)) {
+		ast_mutex_lock_assign(&iflock, lockret);
+		if (lockret) {
 			ast_log(LOG_WARNING, "Unable to lock the interface list\n");
 			continue;
 		}
@@ -1101,10 +1104,12 @@
 
 static int restart_monitor()
 {
+	int lockret;
 	/* If we're supposed to be stopped -- stay stopped */
 	if (monitor_thread == AST_PTHREADT_STOP)
 		return 0;
-	if (ast_mutex_lock(&monlock)) {
+	ast_mutex_lock_assign(&monlock, lockret);
+	if (lockret) {
 		ast_log(LOG_WARNING, "Unable to lock monitor\n");
 		return -1;
 	}
@@ -1114,7 +1119,8 @@
 		return -1;
 	}
 	if (monitor_thread != AST_PTHREADT_NULL) {
-		if (ast_mutex_lock(&iflock)) {
+		ast_mutex_lock_assign(&iflock, lockret);
+		if (lockret) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_WARNING, "Unable to lock the interface list\n");
 			return -1;
@@ -1202,9 +1208,10 @@
 	struct phone_pvt *p;
 	struct ast_channel *tmp = NULL;
 	char *name = data;
-
+	int lockret;
 	/* Search for an unowned channel */
-	if (ast_mutex_lock(&iflock)) {
+	ast_mutex_lock_assign(&iflock, lockret);
+	if (lockret) {
 		ast_log(LOG_ERROR, "Unable to lock interface list???\n");
 		return NULL;
 	}
@@ -1263,10 +1270,12 @@
 static int __unload_module(void)
 {
 	struct phone_pvt *p, *pl;
+	int lockret;
 	/* First, take us out of the channel loop */
 	if (cur_tech)
 		ast_channel_unregister(cur_tech);
-	if (!ast_mutex_lock(&iflock)) {
+	ast_mutex_lock_assign(&iflock, lockret);
+	if (!lockret) {
 		/* Hangup all interfaces if they have an owner */
 		p = iflist;
 		while(p) {
@@ -1280,7 +1289,8 @@
 		ast_log(LOG_WARNING, "Unable to lock the monitor\n");
 		return -1;
 	}
-	if (!ast_mutex_lock(&monlock)) {
+	ast_mutex_lock_assign(&monlock, lockret);
+	if (!lockret) {
 		if (monitor_thread > AST_PTHREADT_NULL) {
 			monitor = 0;
 			while (pthread_kill(monitor_thread, SIGURG) == 0)
@@ -1294,7 +1304,8 @@
 		return -1;
 	}
 
-	if (!ast_mutex_lock(&iflock)) {
+	ast_mutex_lock_assign(&iflock, lockret);
+	if (!lockret) {
 		/* Destroy all the interfaces and free their memory */
 		p = iflist;
 		while(p) {
@@ -1328,6 +1339,8 @@
 	struct phone_pvt *tmp;
 	int mode = MODE_IMMEDIATE;
 	int txgain = DEFAULT_GAIN, rxgain = DEFAULT_GAIN; /* default gain 1.0 */
+	int lockret;
+	
 	cfg = ast_config_load(config);
 
 	/* We *must* have a config file otherwise stop immediately */
@@ -1335,7 +1348,8 @@
 		ast_log(LOG_ERROR, "Unable to load config %s\n", config);
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	if (ast_mutex_lock(&iflock)) {
+	ast_mutex_lock_assign(&iflock, lockret);
+	if (lockret) {
 		/* It's a little silly to lock it, but we mind as well just to be sure */
 		ast_log(LOG_ERROR, "Unable to lock interface list???\n");
 		return AST_MODULE_LOAD_FAILURE;

Modified: team/murf/mtxprof4/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/mtxprof4/channels/chan_sip.c?view=diff&rev=132240&r1=132239&r2=132240
==============================================================================
--- team/murf/mtxprof4/channels/chan_sip.c (original)
+++ team/murf/mtxprof4/channels/chan_sip.c Fri Jul 18 16:33:29 2008
@@ -1136,7 +1136,9 @@
 	int autoframing;
 };
 
-
+/*! this array will store the invocation counts for the 10 
+ funcs that the sched facility initiates. To see if one is
+ going nuts */
 
 /*! \brief Registrations with other SIP proxies */
 struct sip_registry {
@@ -1967,10 +1969,15 @@
 	pkt->retransid = -1;
 
 	if (ast_test_flag(pkt, FLAG_FATAL)) {
-		while(pkt->owner->owner && ast_channel_trylock(pkt->owner->owner)) {
-			DEADLOCK_AVOIDANCE(&pkt->owner->lock);	/* SIP_PVT, not channel */
-		}
-
+ 		int lockret;
+ 		if (pkt->owner->owner)
+ 		{
+ 			ast_channel_trylock_assign(pkt->owner->owner,lockret);
+ 			while(pkt->owner->owner && lockret) {
+				DEADLOCK_AVOIDANCE(&pkt->owner->lock);	/* SIP_PVT, not channel */
+ 				ast_channel_trylock_assign(pkt->owner->owner,lockret);
+ 			}
+  		}
 		if (pkt->owner->owner && !pkt->owner->owner->hangupcause) 
 			pkt->owner->owner->hangupcause = AST_CAUSE_NO_USER_RESPONSE;
 		
@@ -1994,8 +2001,9 @@
 
 	if (pkt->method == SIP_BYE) {
 		/* We're not getting answers on SIP BYE's.  Tear down the call anyway. */
-		if (pkt->owner->owner) 
+		if (pkt->owner->owner){
 			ast_channel_unlock(pkt->owner->owner);
+		}
 		append_history(pkt->owner, "ByeFailure", "Remote peer doesn't respond to bye. Destroying call anyway.");
 		ast_set_flag(&pkt->owner->flags[0], SIP_NEEDDESTROY);
 	}
@@ -2015,8 +2023,9 @@
 		pkt = NULL;
 	} else
 		ast_log(LOG_WARNING, "Weird, couldn't find packet owner!\n");
-	if (pkt)
+	if (pkt) {
 		ast_mutex_unlock(&pkt->owner->lock);
+	}
 	return 0;
 }
 
@@ -2940,12 +2949,14 @@
 static int auto_congest(const void *nothing)
 {
 	struct sip_pvt *p = (struct sip_pvt *)nothing;
-
+	
 	ast_mutex_lock(&p->lock);
 	p->initid = -1;
 	if (p->owner) {
+		int lockret;
 		/* XXX fails on possible deadlock */
-		if (!ast_channel_trylock(p->owner)) {
+		ast_channel_trylock_assign(p->owner,lockret);
+		if (!lockret) {
 			ast_log(LOG_NOTICE, "Auto-congesting %s\n", p->owner->name);
 			append_history(p, "Cong", "Auto-congesting (timer)");
 			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
@@ -3101,15 +3112,17 @@
 
 	/* Unlink us from the owner if we have one */
 	if (p->owner) {
-		if (lockowner)
+		if (lockowner) {
 			ast_channel_lock(p->owner);
+		}
 		if (option_debug)
 			ast_log(LOG_DEBUG, "Detaching from %s\n", p->owner->name);
 		p->owner->tech_pvt = NULL;
 		/* Make sure that the channel knows its backend is going away */
 		p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
-		if (lockowner)
+		if (lockowner) {
 			ast_channel_unlock(p->owner);
+		}
 		/* Give the channel a chance to react before deallocation */
 		usleep(1);
 	}
@@ -3314,6 +3327,7 @@
 		ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event);
 	}
 	if (p) {
+		ast_log(LOG_NOTICE,"device state changed called from here 1\n");
 		ast_device_state_changed("SIP/%s", p->name);
 		ASTOBJ_UNREF(p, sip_destroy_peer);
 	} else /* u must be set */
@@ -7280,7 +7294,7 @@
 
 		while ((individual_hint = strsep(&hint2, "&"))) {
 			hint_count++;
-
+			ast_log(LOG_NOTICE,"Calling ast_device_state\n");
 			if (ast_device_state(individual_hint) == AST_DEVICE_UNAVAILABLE)
 				unavailable_count++;
 		}
@@ -8625,6 +8639,7 @@
 		peer->onHold--;
 
 	/* Request device state update */
+	ast_log(LOG_NOTICE,"device state changed called from here 3\n");
 	ast_device_state_changed("SIP/%s", peer->name);
 
 	return;
@@ -8814,6 +8829,7 @@
 		}
 	}
 	if (!res) {
+		ast_log(LOG_NOTICE,"device state changed called from here 4\n");
 		ast_device_state_changed("SIP/%s", peer->name);
 	}
 	if (res < 0) {
@@ -9024,7 +9040,8 @@
 		if (!strcmp(sip_pvt_ptr->callid, callid)) {
 			int match = 1;
 			char *ourtag = sip_pvt_ptr->tag;
-
+			int lockret;
+			
 			/* Go ahead and lock it (and its owner) before returning */
 			ast_mutex_lock(&sip_pvt_ptr->lock);
 
@@ -9046,8 +9063,12 @@
 					sip_pvt_ptr->theirtag, sip_pvt_ptr->tag);
 
 			/* deadlock avoidance... */
-			while (sip_pvt_ptr->owner && ast_channel_trylock(sip_pvt_ptr->owner)) {
-				DEADLOCK_AVOIDANCE(&sip_pvt_ptr->lock);
+			if (sip_pvt_ptr->owner) {
+				ast_channel_trylock_assign(sip_pvt_ptr->owner,lockret);
+				while (sip_pvt_ptr->owner && lockret) {
+					DEADLOCK_AVOIDANCE(&sip_pvt_ptr->lock);
+					ast_channel_trylock_assign(sip_pvt_ptr->owner,lockret);
+				}
 			}
 			break;
 		}
@@ -13238,6 +13259,7 @@
 	struct ast_channel *transferee, *transferer;
 		/* Chan2m: The transferer, chan1m: The transferee */
 	pthread_t th;
+	int lockret;
 
 	transferee = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, chan1->accountcode, chan1->exten, chan1->context, chan1->amaflags, "Parking/%s", chan1->name);
 	transferer = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, chan2->accountcode, chan2->exten, chan2->context, chan2->amaflags, "SIPPeer/%s", chan2->name);
@@ -13275,9 +13297,11 @@
 	/* Prepare for taking over the channel.  Go ahead and grab this channel
 	 * lock here to avoid a deadlock with callbacks into the channel driver
 	 * that hold the channel lock and want the pvt lock.  */
-	while (ast_channel_trylock(chan2)) {
+	ast_channel_trylock_assign(chan2,lockret);
+	while (lockret) {
 		struct sip_pvt *pvt = chan2->tech_pvt;
 		DEADLOCK_AVOIDANCE(&pvt->lock);
+		ast_channel_trylock_assign(chan2,lockret);
 	}
 	ast_channel_masquerade(transferer, chan2);
 	ast_channel_unlock(chan2);
@@ -13689,8 +13713,9 @@
 	if (option_debug > 3)
 		ast_log(LOG_DEBUG, "Invite/Replaces: preparing to masquerade %s into %s\n", c->name, replacecall->name);
 	/* Unlock clone, but not original (replacecall) */
-	if (!oneleggedreplace)
+	if (!oneleggedreplace) {
 		ast_channel_unlock(c);
+	}
 
 	/* Unlock PVT */
 	ast_mutex_unlock(&p->refer->refer_call->lock);
@@ -13722,8 +13747,9 @@
 			ast_log(LOG_WARNING, "Invite/Replace:  Could not read frame from RING channel \n");
 		}
 		c->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
-		if (!oneleggedreplace)
+		if (!oneleggedreplace) {
 			ast_channel_unlock(replacecall);
+		}
 	} else {	/* Bridged call, UP channel */
 		if ((f = ast_read(replacecall))) {	/* Force the masq to happen */
 			/* Masq ok */
@@ -13758,8 +13784,9 @@
 	}
 
 	ast_channel_unlock(p->owner);	/* Unlock new owner */
-	if (!oneleggedreplace)
+	if (!oneleggedreplace) {
 		ast_mutex_unlock(&p->lock);	/* Unlock SIP structure */
+	}
 
 	/* The call should be down with no ast_channel, so hang it up */
 	c->tech_pvt = NULL;
@@ -14084,11 +14111,12 @@
 
 			/* Save Record-Route for any later requests we make on this dialogue */
 			build_route(p, req, 0);
-
+#ifdef WHAT_IF_WE_DONT_LOCK_THE_CHANNEL
 			if (c) {
 				/* Pre-lock the call */
 				ast_channel_lock(c);
 			}
+#endif
 		}
 	} else {
 		if (option_debug > 1 && sipdebug) {
@@ -14122,10 +14150,29 @@
 			p->invitestate = INV_PROCEEDING;
 			ast_setstate(c, AST_STATE_RING);
 			if (strcmp(p->exten, ast_pickup_ext())) {	/* Call to extension -start pbx on this call */
+				static int pbx_mark = -1;
 				enum ast_pbx_result res;
-

[... 1950 lines stripped ...]



More information about the asterisk-commits mailing list