]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Prevent a race condition when the bridge technology changes. This change was
authorMatthew Nicholson <mnicholson@digium.com>
Mon, 12 Sep 2011 15:49:24 +0000 (15:49 +0000)
committerMatthew Nicholson <mnicholson@digium.com>
Mon, 12 Sep 2011 15:49:24 +0000 (15:49 +0000)
ported from asterisk 10.

ASTERISK-18155

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

bridges/bridge_multiplexed.c

index e97e154608acbde7ff279a30054695bab0933882..b6d376fc5aa2a10c4c0c7ba4ffd0f6f015403789 100644 (file)
@@ -223,6 +223,9 @@ static void *multiplexed_thread_function(void *data)
                winner = ast_waitfor_nandfds(multiplexed_thread->chans, multiplexed_thread->service_count, &fds, 1, NULL, &outfd, &to);
                multiplexed_thread->waiting = 0;
                ao2_lock(multiplexed_thread);
+               if (multiplexed_thread->thread == AST_PTHREADT_STOP) {
+                       break;
+               }
 
                if (outfd > -1) {
                        int nudge;
@@ -234,7 +237,21 @@ static void *multiplexed_thread_function(void *data)
                        }
                }
                if (winner && winner->bridge) {
-                       ast_bridge_handle_trip(winner->bridge, NULL, winner, -1);
+                       struct ast_bridge *bridge = winner->bridge;
+                       int stop = 0;
+                       ao2_unlock(multiplexed_thread);
+                       while ((bridge = winner->bridge) && ao2_trylock(bridge)) {
+                               sched_yield();
+                               if (multiplexed_thread->thread == AST_PTHREADT_STOP) {
+                                       stop = 1;
+                                       break;
+                               }
+                       }
+                       if (!stop && bridge) {
+                               ast_bridge_handle_trip(bridge, NULL, winner, -1);
+                               ao2_unlock(bridge);
+                       }
+                       ao2_lock(multiplexed_thread);
                }
        }