From f33e9c6edefce164cd1edfb05412c103a0d51fea Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Mar 2011 20:50:33 -0600 Subject: [PATCH] FS-2966 I already fixed this in the wait_for_state, so i copied the same fix to wait_for_state_timeout, the lua one needed a similar call to wait for the state to change to avoid a race, both of you should be fixed with this patch --- src/switch_channel.c | 8 +++++--- src/switch_cpp.cpp | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/switch_channel.c b/src/switch_channel.c index 179f63da79..4341ea9214 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1206,18 +1206,20 @@ SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, sw } -SWITCH_DECLARE(void) switch_channel_wait_for_state_timeout(switch_channel_t *other_channel, switch_channel_state_t want_state, uint32_t timeout) +SWITCH_DECLARE(void) switch_channel_wait_for_state_timeout(switch_channel_t *channel, switch_channel_state_t want_state, uint32_t timeout) { switch_channel_state_t state; uint32_t count = 0; for (;;) { - state = switch_channel_get_running_state(other_channel); + state = switch_channel_get_running_state(channel); - if (state >= want_state) { + if ((channel->state == channel->running_state && channel->running_state == want_state) || channel->state >= CS_HANGUP) { break; } + switch_cond_next(); + if (++count >= timeout) { break; } diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index c62946b760..7d2f281a89 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -516,6 +516,7 @@ SWITCH_DECLARE_CONSTRUCTOR CoreSession::CoreSession(char *nuuid, CoreSession *a_ switch_set_flag(this, S_HUP); uuid = strdup(switch_core_session_get_uuid(session)); switch_channel_set_state(switch_core_session_get_channel(session), CS_SOFT_EXECUTE); + switch_channel_wait_for_state(switch_core_session_get_channel(session), switch_core_session_get_channel(a_leg->session), CS_SOFT_EXECUTE); } } }