diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-09-28 05:30:22 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-09-28 05:30:22 +0000 |
commit | 238faded53089c38d6396aaa60c0bbbf2227654b (patch) | |
tree | 9d7789bfa57bb32964e61e1fcbcd942518981f15 /main/channel.c | |
parent | 53054e222d379cc07e349447b9bff55bcdd453c4 (diff) |
Avoid a deadlock with ALL of the locks in the masquerade function, not just the
pairs of channels. (Closes issue #10406)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@84049 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/channel.c')
-rw-r--r-- | main/channel.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/main/channel.c b/main/channel.c index 1ffa06416..0ae9af4b0 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3410,7 +3410,11 @@ int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *pe int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone) { int res = -1; - struct ast_channel *final_orig = original, *final_clone = clone; + struct ast_channel *final_orig, *final_clone; + +retrymasq: + final_orig = original; + final_clone = clone; ast_channel_lock(original); while (ast_channel_trylock(clone)) { @@ -3428,11 +3432,19 @@ int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clo final_clone = clone->_bridge; if ((final_orig != original) || (final_clone != clone)) { - ast_channel_lock(final_orig); - while (ast_channel_trylock(final_clone)) { + /* Lots and lots of deadlock avoidance. The main one we're competing with + * is ast_write(), which locks channels recursively, when working with a + * proxy channel. */ + if (ast_channel_trylock(final_orig)) { + ast_channel_unlock(clone); + ast_channel_unlock(original); + goto retrymasq; + } + if (ast_channel_trylock(final_clone)) { ast_channel_unlock(final_orig); - usleep(1); - ast_channel_lock(final_orig); + ast_channel_unlock(clone); + ast_channel_unlock(original); + goto retrymasq; } ast_channel_unlock(clone); ast_channel_unlock(original); |