From e697bf8d262cbfcd5920b3f3ebbbc54da47809a9 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 26 Feb 2008 20:31:53 +0000 Subject: [PATCH] update git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7745 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 22 +++++++----------- src/mod/endpoints/mod_sofia/sofia_glue.c | 5 ++-- src/switch_core_session.c | 7 ++++-- src/switch_core_state_machine.c | 29 ++++++++++++++++-------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 54deab6855..b0b87faebf 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -707,8 +707,6 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi private_object_t *tech_pvt = switch_core_session_get_private(session); switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_mutex_lock(tech_pvt->flag_mutex); - if (switch_channel_get_state(channel) >= CS_HANGUP || !tech_pvt) { status = SWITCH_STATUS_FALSE; goto end; @@ -717,7 +715,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (msg->message_id == SWITCH_MESSAGE_INDICATE_ANSWER || msg->message_id == SWITCH_MESSAGE_INDICATE_PROGRESS) { const char *var; if ((var = switch_channel_get_variable(channel, SOFIA_SECURE_MEDIA_VARIABLE)) && switch_true(var)) { - switch_set_flag(tech_pvt, TFLAG_SECURE); + switch_set_flag_locked(tech_pvt, TFLAG_SECURE); } } @@ -789,7 +787,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending media re-direct:\n%s\n", msg->string_arg); tech_pvt->local_sdp_str = switch_core_session_strdup(session, msg->string_arg); - switch_set_flag(tech_pvt, TFLAG_SENT_UPDATE); + switch_set_flag_locked(tech_pvt, TFLAG_SENT_UPDATE); sofia_glue_do_invite(session); } break; @@ -828,7 +826,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi case SWITCH_MESSAGE_INDICATE_HOLD: { - switch_set_flag(tech_pvt, TFLAG_SIP_HOLD); + switch_set_flag_locked(tech_pvt, TFLAG_SIP_HOLD); sofia_glue_do_invite(session); } break; @@ -850,7 +848,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi private_object_t *a_tech_pvt = switch_core_session_get_private(a_session); private_object_t *b_tech_pvt = switch_core_session_get_private(b_session); - switch_set_flag(a_tech_pvt, TFLAG_REINVITE); + switch_set_flag_locked(a_tech_pvt, TFLAG_REINVITE); a_tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(a_session, b_tech_pvt->remote_sdp_audio_ip); a_tech_pvt->remote_sdp_audio_port = b_tech_pvt->remote_sdp_audio_port; a_tech_pvt->local_sdp_audio_ip = switch_core_session_strdup(a_session, b_tech_pvt->local_sdp_audio_ip); @@ -886,7 +884,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (msg->string_arg) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Re-directing to %s\n", msg->string_arg); nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(msg->string_arg), TAG_END()); - switch_set_flag(tech_pvt, TFLAG_BYE); + switch_set_flag_locked(tech_pvt, TFLAG_BYE); } break; @@ -963,7 +961,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi nua_respond(tech_pvt->nh, code, reason, TAG_IF(to_uri, SIPTAG_CONTACT_STR(to_uri)), SIPTAG_SUPPORTED_STR(NULL), SIPTAG_ACCEPT_STR(NULL), TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)), TAG_END()); - switch_set_flag(tech_pvt, TFLAG_BYE); + switch_set_flag_locked(tech_pvt, TFLAG_BYE); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Responding with %d %s\n", code, reason); @@ -981,7 +979,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi } else { nua_respond(tech_pvt->nh, code, reason, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END()); } - switch_set_flag(tech_pvt, TFLAG_BYE); + switch_set_flag_locked(tech_pvt, TFLAG_BYE); } } @@ -1000,7 +998,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi { if (!switch_test_flag(tech_pvt, TFLAG_ANS) && !switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) { - switch_set_flag(tech_pvt, TFLAG_EARLY_MEDIA); + switch_set_flag_locked(tech_pvt, TFLAG_EARLY_MEDIA); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Asked to send early media by %s\n", msg->from); /* Transmit 183 Progress with SDP */ @@ -1061,10 +1059,6 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi end: - //xxxbot - - switch_mutex_unlock(tech_pvt->flag_mutex); - return status; } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 8e5d58de7f..b3f55490c6 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -1425,7 +1425,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f switch_assert(tech_pvt != NULL); - switch_mutex_lock(tech_pvt->flag_mutex); + switch_core_session_signal_lock(tech_pvt->session); if (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE)) { status = SWITCH_STATUS_SUCCESS; @@ -1665,7 +1665,8 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f end: - switch_mutex_unlock(tech_pvt->flag_mutex); + switch_core_session_signal_unlock(tech_pvt->session); + return status; } diff --git a/src/switch_core_session.c b/src/switch_core_session.c index d5c06b7ea2..cad418fa15 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -343,13 +343,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_ switch_assert(session != NULL); + if (switch_channel_get_state(session->channel) >= CS_HANGUP) { + return SWITCH_STATUS_FALSE; + } + if ((status = switch_core_session_read_lock(session)) != SWITCH_STATUS_SUCCESS) { return status; } - switch_core_session_signal_lock(session); - + if (session->endpoint_interface->io_routines->receive_message) { status = session->endpoint_interface->io_routines->receive_message(session, message); } diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index 0a359e2afd..76dd08ea49 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -414,6 +414,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) break; case CS_DONE: goto done; + /* HANGUP INIT RING and RESET are all short term so we signal lock during their callbacks */ case CS_HANGUP: /* Deactivate and end the thread */ { const char *var = switch_channel_get_variable(session->channel, SWITCH_PROCESS_CDR_VARIABLE); @@ -431,35 +432,43 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) do_extra_handlers = 0; } } - + switch_core_session_signal_lock(session); STATE_MACRO(hangup, "HANGUP"); + switch_core_session_signal_unlock(session); } goto done; - case CS_INIT: /* Basic setup tasks */ + case CS_INIT: /* Basic setup tasks */ + switch_core_session_signal_lock(session); STATE_MACRO(init, "INIT"); + switch_core_session_signal_unlock(session); break; - case CS_RING: /* Look for a dialplan and find something to do */ + case CS_RING: /* Look for a dialplan and find something to do */ + switch_core_session_signal_lock(session); STATE_MACRO(ring, "RING"); + switch_core_session_signal_unlock(session); break; - case CS_RESET: /* Reset */ + case CS_RESET: /* Reset */ + switch_core_session_signal_lock(session); STATE_MACRO(reset, "RESET"); + switch_core_session_signal_unlock(session); break; - case CS_EXECUTE: /* Execute an Operation */ + /* These other states are intended for prolonged durations so we do not signal lock for them */ + case CS_EXECUTE: /* Execute an Operation */ STATE_MACRO(execute, "EXECUTE"); break; - case CS_LOOPBACK: /* loop all data back to source */ + case CS_LOOPBACK: /* loop all data back to source */ STATE_MACRO(loopback, "LOOPBACK"); break; - case CS_TRANSMIT: /* send/recieve data to/from another channel */ + case CS_TRANSMIT: /* send/recieve data to/from another channel */ STATE_MACRO(transmit, "TRANSMIT"); break; - case CS_PARK: /* wait in limbo */ + case CS_PARK: /* wait in limbo */ STATE_MACRO(park, "PARK"); break; - case CS_HOLD: /* wait in limbo */ + case CS_HOLD: /* wait in limbo */ STATE_MACRO(hold, "HOLD"); break; - case CS_HIBERNATE: /* sleep */ + case CS_HIBERNATE: /* sleep */ STATE_MACRO(hibernate, "HIBERNATE"); break; case CS_NONE: