diff --git a/channels/chan_local.c b/channels/chan_local.c index f574eab322..617cd2eb9f 100644 --- a/channels/chan_local.c +++ b/channels/chan_local.c @@ -193,13 +193,13 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra while (other && ast_channel_trylock(other)) { ast_mutex_unlock(&p->lock); if (us && us_locked) { - ast_channel_unlock(us); - } - usleep(1); - if (us && us_locked) { - ast_channel_lock(us); + do { + CHANNEL_DEADLOCK_AVOIDANCE(us); + } while (ast_mutex_trylock(&p->lock)); + } else { + usleep(1); + ast_mutex_lock(&p->lock); } - ast_mutex_lock(&p->lock); other = isoutbound ? p->owner : p->chan; } @@ -516,7 +516,12 @@ static int local_hangup(struct ast_channel *ast) if (!p) return -1; - ast_mutex_lock(&p->lock); + while (ast_mutex_trylock(&p->lock)) { + ast_channel_unlock(ast); + usleep(1); + ast_channel_lock(ast); + } + if (p->chan && ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE)) ast_set_flag(p->chan, AST_FLAG_ANSWERED_ELSEWHERE); isoutbound = IS_OUTBOUND(ast, p);