aboutsummaryrefslogtreecommitdiffstats
path: root/main/channel.c
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-05 23:29:29 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-05 23:29:29 +0000
commit711f7f64084ed1bc63e78752b6b68ee0c3972cee (patch)
treebfa7f1a5fdcc49a003bb66c7fd5529ef73f3d36d /main/channel.c
parentaf44a1b17a6864b6772c7384dca8552b8b7dc0ad (diff)
Reworked deadlock avoidance in __ast_read. Restored audio to
callback agents. (closes issue #11071, reported by callguy, patched by me, tested by callguy and Ted Brown) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@88826 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/channel.c')
-rw-r--r--main/channel.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/main/channel.c b/main/channel.c
index 840575f34..00e57117b 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -2181,14 +2181,20 @@ static void ast_read_generator_actions(struct ast_channel *chan, struct ast_fram
static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
{
struct ast_frame *f = NULL; /* the return value */
- struct ast_channel *base = NULL;
int blah;
int prestate;
+ int count = 0;
/* this function is very long so make sure there is only one return
- * point at the end (there is only one exception to this).
+ * point at the end (there are only two exceptions to this).
*/
- ast_channel_lock(chan);
+ while(ast_channel_trylock(chan)) {
+ if(count++ > 10)
+ /*cannot goto done since the channel is not locked*/
+ return &ast_null_frame;
+ usleep(1);
+ }
+
if (chan->masq) {
if (ast_do_masquerade(chan))
ast_log(LOG_WARNING, "Failed to perform masquerade\n");
@@ -2205,23 +2211,6 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
}
prestate = chan->_state;
- /* Check if there's an underlying channel */
- if (chan->tech->get_base_channel && (base = chan->tech->get_base_channel(chan)) != chan) {
- int count = 0;
- while (!base || ast_mutex_trylock(&base->lock)) {
- if (count++ > 10) {
- f = &ast_null_frame;
- goto done;
- }
- ast_mutex_unlock(&chan->lock);
- usleep(1);
- ast_mutex_lock(&chan->lock);
- base = chan->tech->get_base_channel(chan);
- }
- ast_mutex_unlock(&chan->lock);
- chan = base;
- }
-
if (!ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF | AST_FLAG_IN_DTMF) &&
!ast_strlen_zero(chan->dtmfq) &&
(ast_tvzero(chan->dtmf_tv) || ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) > AST_MIN_DTMF_GAP) ) {