From abc56833adfe8c5fc93840d3f596443c32496d17 Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Mon, 10 Nov 2008 21:07:39 +0000 Subject: [PATCH] Channel drivers assume that when their indicate callback is invoked, that the channel on which the callback was called is locked. This patch corrects an instance in chan_agent where a channel's indicate callback is called directly without first locking the channel. This was leading to some observed locking issues in chan_local, but considering that all channel drivers operate under the same expectations, the generic fix in chan_agent is the right way to go. AST-126 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@155861 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_agent.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/channels/chan_agent.c b/channels/chan_agent.c index 62a5c2d1c6..0e266fa5df 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -666,9 +666,15 @@ static int agent_indicate(struct ast_channel *ast, int condition, const void *da struct agent_pvt *p = ast->tech_pvt; int res = -1; ast_mutex_lock(&p->lock); - if (p->chan && !ast_check_hangup(p->chan)) - res = p->chan->tech->indicate ? p->chan->tech->indicate(p->chan, condition, data, datalen) : -1; - else + if (p->chan && !ast_check_hangup(p->chan)) { + while (ast_channel_trylock(p->chan)) { + ast_channel_unlock(ast); + usleep(1); + ast_channel_lock(ast); + } + res = p->chan->tech->indicate ? p->chan->tech->indicate(p->chan, condition, data, datalen) : -1; + ast_channel_unlock(p->chan); + } else res = 0; ast_mutex_unlock(&p->lock); return res;