[asterisk-commits] tilghman: branch 1.4 r84049 - /branches/1.4/main/channel.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Sep 28 00:30:24 CDT 2007
Author: tilghman
Date: Fri Sep 28 00:30:22 2007
New Revision: 84049
URL: http://svn.digium.com/view/asterisk?view=rev&rev=84049
Log:
Avoid a deadlock with ALL of the locks in the masquerade function, not just the
pairs of channels. (Closes issue #10406)
Modified:
branches/1.4/main/channel.c
Modified: branches/1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/channel.c?view=diff&rev=84049&r1=84048&r2=84049
==============================================================================
--- branches/1.4/main/channel.c (original)
+++ branches/1.4/main/channel.c Fri Sep 28 00:30:22 2007
@@ -3410,7 +3410,11 @@
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 @@
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);
More information about the asterisk-commits
mailing list