From 21d9b7996ba79cf65a7be32348f8ac293d59e0a3 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 5 Oct 2007 16:44:21 +0000 Subject: [PATCH] Do deadlock avoidance in a couple more places. You can't lock two channels at the same time without doing extra work to make sure it succeeds. (closes issue #10895, patch by me) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@84783 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_zap.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/channels/chan_zap.c b/channels/chan_zap.c index f490c047ad..90dae43453 100644 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -3167,7 +3167,11 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann return AST_BRIDGE_FAILED_NOWARN; ast_mutex_lock(&c0->lock); - ast_mutex_lock(&c1->lock); + while (ast_mutex_trylock(&c1->lock)) { + ast_mutex_unlock(&c0->lock); + usleep(1); + ast_mutex_lock(&c0->lock); + } p0 = c0->tech_pvt; p1 = c1->tech_pvt; @@ -3335,7 +3339,12 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann /* 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); - ast_mutex_lock(&c1->lock); + while (ast_mutex_trylock(&c1->lock)) { + ast_mutex_unlock(&c0->lock); + usleep(1); + ast_mutex_lock(&c0->lock); + } + p0 = c0->tech_pvt; p1 = c1->tech_pvt; -- 2.47.3