]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Do deadlock avoidance in a couple more places. You can't lock two channels
authorRussell Bryant <russell@russellbryant.com>
Fri, 5 Oct 2007 16:44:21 +0000 (16:44 +0000)
committerRussell Bryant <russell@russellbryant.com>
Fri, 5 Oct 2007 16:44:21 +0000 (16:44 +0000)
at the same time without doing extra work to make sure it succeeds.
(closes issue #10895, patch by me)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@84783 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_zap.c

index f490c047adae7280d80b6797717ac1ddd0abbc32..90dae434532c65454b9af47a9f69ddffaa5eab89 100644 (file)
@@ -3167,7 +3167,11 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann
                return AST_BRIDGE_FAILED_NOWARN;
 
        ast_mutex_lock(&c0->lock);
-       ast_mutex_lock(&c1->lock);
+       while (ast_mutex_trylock(&c1->lock)) {
+               ast_mutex_unlock(&c0->lock);
+               usleep(1);
+               ast_mutex_lock(&c0->lock);
+       }
 
        p0 = c0->tech_pvt;
        p1 = c1->tech_pvt;
@@ -3335,7 +3339,12 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann
                /* Here's our main loop...  Start by locking things, looking for private parts, 
                   and then balking if anything is wrong */
                ast_mutex_lock(&c0->lock);
-               ast_mutex_lock(&c1->lock);
+               while (ast_mutex_trylock(&c1->lock)) {
+                       ast_mutex_unlock(&c0->lock);
+                       usleep(1);
+                       ast_mutex_lock(&c0->lock);
+               }
+
                p0 = c0->tech_pvt;
                p1 = c1->tech_pvt;