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
This commit is contained in:
Matthew Nicholson
2011-09-12 15:49:24 +00:00
parent 263a410438
commit 828a733f58

View 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);
}
}