From e9221b062ee53f38cb23f21572b0d3d96c4829e5 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Tue, 9 Oct 2007 22:21:49 +0000 Subject: Merged revisions 85158 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r85158 | tilghman | 2007-10-09 16:55:06 -0500 (Tue, 09 Oct 2007) | 5 lines This commit fixes the following issues: - Deadlock in ast_write (issue #10406) - Deadlock in ast_read (issue #10406) - Possible mutex initialization error in lock.h (issue #10571) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@85176 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/channel.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'main/channel.c') diff --git a/main/channel.c b/main/channel.c index 9d8fd0dd1..9cdf0521d 100644 --- a/main/channel.c +++ b/main/channel.c @@ -2110,6 +2110,7 @@ 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; @@ -2133,6 +2134,23 @@ 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) ) { @@ -2869,7 +2887,22 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr) ast_log(LOG_WARNING, "Failed to write data to channel monitor write stream\n"); } } - res = f ? chan->tech->write(chan, f) : 0; + + if (f) { + struct ast_channel *base = NULL; + if (!chan->tech->get_base_channel || chan == chan->tech->get_base_channel(chan)) + res = chan->tech->write(chan, f); + else { + while (chan->tech->get_base_channel && (((base = chan->tech->get_base_channel(chan)) && ast_mutex_trylock(&base->lock)) || base == NULL)) { + ast_mutex_unlock(&chan->lock); + usleep(1); + ast_mutex_lock(&chan->lock); + } + res = base->tech->write(base, f); + ast_mutex_unlock(&base->lock); + } + } else + res = 0; break; case AST_FRAME_NULL: case AST_FRAME_IAX: -- cgit v1.2.3