From 828a733f587f64c2a1c92125c572754e14457f63 Mon Sep 17 00:00:00 2001 From: Matthew Nicholson Date: Mon, 12 Sep 2011 15:49:24 +0000 Subject: [PATCH] Prevent a race condition when the bridge technology changes. This change was 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 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bridges/bridge_multiplexed.c b/bridges/bridge_multiplexed.c index e97e154608..b6d376fc5a 100644 --- a/bridges/bridge_multiplexed.c +++ b/bridges/bridge_multiplexed.c @@ -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); } } -- 2.47.2