chan_agent: Fix agent_indicate() locking.

Avoid deadlock potential with local channels and simplify the locking.
........

Merged revisions 378427 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 378428 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@378429 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett 2013-01-03 17:48:14 +00:00
parent 7739ed9989
commit 11571714fe
1 changed files with 11 additions and 12 deletions

View File

@ -784,22 +784,21 @@ static int agent_indicate(struct ast_channel *ast, int condition, const void *da
{ {
struct agent_pvt *p = ast_channel_tech_pvt(ast); struct agent_pvt *p = ast_channel_tech_pvt(ast);
int res = -1; int res = -1;
ast_mutex_lock(&p->lock); ast_mutex_lock(&p->lock);
if (p->chan && !ast_check_hangup(p->chan)) { if (p->chan && !ast_check_hangup(p->chan)) {
while (ast_channel_trylock(p->chan)) { ast_channel_unlock(ast);
if ((res = ast_channel_unlock(ast))) { ast_channel_lock(p->chan);
ast_log(LOG_ERROR, "chan_agent bug! Channel was not locked upon entry to agent_indicate: %s\n", res > 0 ? strerror(res) : "Bad ao2obj data"); res = ast_channel_tech(p->chan)->indicate
ast_mutex_unlock(&p->lock); ? ast_channel_tech(p->chan)->indicate(p->chan, condition, data, datalen)
return -1; : -1;
}
usleep(1);
ast_channel_lock(ast);
}
res = ast_channel_tech(p->chan)->indicate ? ast_channel_tech(p->chan)->indicate(p->chan, condition, data, datalen) : -1;
ast_channel_unlock(p->chan); ast_channel_unlock(p->chan);
} else ast_mutex_unlock(&p->lock);
ast_channel_lock(ast);
} else {
ast_mutex_unlock(&p->lock);
res = 0; res = 0;
ast_mutex_unlock(&p->lock); }
return res; return res;
} }