aboutsummaryrefslogtreecommitdiffstats
path: root/main/channel.c
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2007-12-18 17:02:48 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2007-12-18 17:02:48 +0000
commit60fb21f9cdf0d9f82a3676bf83b9e0716de62e8e (patch)
treeb5cf61b02f436c763617e5e08f40cc8f743a3459 /main/channel.c
parentc6fdb3f3bc1aee4ded35895a0cc2be46e4a9f03f (diff)
Rework deadlock avoidance used in ast_write, since it meant that agent channels which were being monitored
had one audio file recorded and one empty audio file saved. (closes issue #11529, reported by atis patched by me) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@93625 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/channel.c')
-rw-r--r--main/channel.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/main/channel.c b/main/channel.c
index d242ea17f..d6c22cd74 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -2805,10 +2805,20 @@ int ast_write_video(struct ast_channel *chan, struct ast_frame *fr)
int ast_write(struct ast_channel *chan, struct ast_frame *fr)
{
int res = -1;
+ int count = 0;
struct ast_frame *f = NULL;
+ /*Deadlock avoidance*/
+ while(ast_channel_trylock(chan)) {
+ /*cannot goto done since the channel is not locked*/
+ if(count++ > 10) {
+ if(option_debug)
+ ast_log(LOG_DEBUG, "Deadlock avoided for write to channel '%s'\n", chan->name);
+ return 0;
+ }
+ usleep(1);
+ }
/* Stop if we're a zombie or need a soft hangup */
- ast_channel_lock(chan);
if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
goto done;
@@ -2973,20 +2983,9 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
/* and now put it through the regular translator */
f = (chan->writetrans) ? ast_translate(chan->writetrans, f, 0) : f;
}
- 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
+ if (f)
+ res = chan->tech->write(chan,f);
+ else
res = 0;
break;
case AST_FRAME_NULL: