From 81c1dc0de94401cc736651ed6c1ca51f307b7f59 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 30 Oct 2008 22:40:39 +0000 Subject: [PATCH] redo some stuff git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10206 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/private/switch_core_pvt.h | 1 - src/include/switch_core.h | 3 -- src/mod/endpoints/mod_iax/mod_iax.c | 4 -- src/mod/endpoints/mod_sofia/mod_sofia.c | 56 +++++++++++++++++++----- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 6 ++- src/mod/endpoints/mod_sofia/sofia_glue.c | 6 +-- src/switch_channel.c | 6 ++- src/switch_core_rwlock.c | 9 ---- src/switch_core_session.c | 11 ++--- src/switch_core_state_machine.c | 9 +--- 11 files changed, 60 insertions(+), 52 deletions(-) diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index f3c5a9bdd4..b19c65e956 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -121,7 +121,6 @@ struct switch_core_session { switch_mutex_t *mutex; switch_mutex_t *resample_mutex; - switch_mutex_t *signal_mutex; switch_thread_cond_t *cond; switch_thread_rwlock_t *rwlock; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 9de85e364e..3036f17953 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -297,9 +297,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void); ///\ingroup core1 ///\{ -SWITCH_DECLARE(switch_status_t) switch_core_session_signal_lock(switch_core_session_t *session); -SWITCH_DECLARE(switch_status_t) switch_core_session_signal_unlock(switch_core_session_t *session); - #ifdef SWITCH_DEBUG_RWLOCKS SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock(_In_ switch_core_session_t *session, const char *file, const char *func, int line); #endif diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c index 62d87c08bb..6d65b95cda 100644 --- a/src/mod/endpoints/mod_iax/mod_iax.c +++ b/src/mod/endpoints/mod_iax/mod_iax.c @@ -938,7 +938,6 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) if ((tech_pvt = iax_get_private(iaxevent->session))) { channel = switch_core_session_get_channel(tech_pvt->session); - switch_core_session_signal_lock(tech_pvt->session); } if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) { @@ -1122,9 +1121,6 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime) } iax_event_free(iaxevent); switch_mutex_unlock(globals.mutex); - if (tech_pvt && tech_pvt->session) { - switch_core_session_signal_unlock(tech_pvt->session); - } } } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index e8e106488a..d37c59e0f8 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -292,7 +292,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) switch_core_session_rwunlock(a_session); } - switch_mutex_lock(tech_pvt->profile->flag_mutex); + if (tech_pvt->nh && !switch_test_flag(tech_pvt, TFLAG_BYE)) { char reason[128] = ""; @@ -326,6 +326,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) switch_snprintf(reason, sizeof(reason), "FreeSWITCH;cause=%d;text=\"%s\"", cause, switch_channel_cause2str(cause)); } + switch_mutex_lock(tech_pvt->sofia_mutex); if (switch_test_flag(tech_pvt, TFLAG_ANS)) { if (!tech_pvt->got_bye) { switch_channel_set_variable(channel, "sip_hangup_disposition", "send_bye"); @@ -357,10 +358,12 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) TAG_END()); } } + switch_mutex_unlock(tech_pvt->sofia_mutex); switch_set_flag(tech_pvt, TFLAG_BYE); switch_safe_free(stream.data); } + switch_mutex_lock(tech_pvt->profile->flag_mutex); switch_clear_flag(tech_pvt, TFLAG_IO); tech_pvt->profile->inuse--; switch_mutex_unlock(tech_pvt->profile->flag_mutex); @@ -416,23 +419,21 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) /* This if statement check and handles the 3pcc proxy mode */ if ((tech_pvt->profile->pflags & PFLAG_3PCC_PROXY) && switch_test_flag(tech_pvt, TFLAG_3PCC)) { /* Send the 200 OK */ + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, SIP_200_OK, SIPTAG_CONTACT_STR(tech_pvt->profile->url), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "3PCC-PROXY, Sent a 200 OK, waiting for ACK\n"); /* Unlock the session signal to allow the ack to make it in */ // Maybe we should timeout? - switch_core_session_signal_unlock(session); + while(switch_channel_ready(channel) && !switch_test_flag(tech_pvt, TFLAG_3PCC_HAS_ACK)) { switch_yield(1000); } - // if we never got the ack should we PUNT? - /* Get the lock back before we continue */ - switch_core_session_signal_lock(session); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "3PCC-PROXY, Done waiting for ACK\n"); } @@ -452,7 +453,9 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); + //switch_mutex_lock(tech_pvt->sofia_mutex); //nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); + //switch_mutex_unlock(tech_pvt->sofia_mutex); return SWITCH_STATUS_FALSE; } } @@ -491,7 +494,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) } - + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, SIP_200_OK, NUTAG_AUTOANSWER(0), TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)), @@ -499,7 +502,7 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) SIPTAG_CONTACT_STR(tech_pvt->reply_contact), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END()); - + switch_mutex_unlock(tech_pvt->sofia_mutex); switch_set_flag_locked(tech_pvt, TFLAG_ANS); return SWITCH_STATUS_SUCCESS; @@ -796,7 +799,9 @@ static switch_status_t sofia_send_dtmf(switch_core_session_t *session, const swi case DTMF_INFO: snprintf(message, sizeof(message), "Signal=%c\r\nDuration=%d\r\n", dtmf->digit, dtmf->duration / 8); + switch_mutex_lock(tech_pvt->sofia_mutex); nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/dtmf-relay"), SIPTAG_PAYLOAD_STR(message), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); break; default: break; @@ -831,10 +836,15 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi " \r\n" " \r\n" " \r\n" - " \r\n" " \r\n" " \r\n" " \r\n" " \r\n"; + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n"; + switch_mutex_lock(tech_pvt->sofia_mutex); nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("application/media_control+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END()); - + switch_mutex_unlock(tech_pvt->sofia_mutex); } break; @@ -851,10 +861,12 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (ip && port) { sofia_glue_set_local_sdp(tech_pvt, ip, atoi(port), msg->string_arg, 1); } + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, SIP_200_OK, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); switch_channel_mark_answered(channel); } break; @@ -936,7 +948,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (!switch_strlen_zero(msg->string_arg)) { char message[256] = ""; snprintf(message, sizeof(message), "From:\r\nTo: \"%s\"\r\n", msg->string_arg); + switch_mutex_lock(tech_pvt->sofia_mutex); nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), SIPTAG_PAYLOAD_STR(message), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); } } break; @@ -948,7 +962,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (!switch_strlen_zero(msg->string_arg)) { char message[256] = ""; snprintf(message, sizeof(message), "From:\r\nTo: \"%s\"\r\n", msg->string_arg); + switch_mutex_lock(tech_pvt->sofia_mutex); nua_info(tech_pvt->nh, SIPTAG_CONTENT_TYPE_STR("message/sipfrag"), SIPTAG_PAYLOAD_STR(message), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); } } break; @@ -1007,7 +1023,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi if (!switch_strlen_zero(msg->string_arg)) { if (!switch_channel_test_flag(channel, CF_ANSWERED)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Redirecting to %s\n", msg->string_arg); + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, SIP_302_MOVED_TEMPORARILY, SIPTAG_CONTACT_STR(msg->string_arg), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); switch_set_flag_locked(tech_pvt, TFLAG_BYE); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Too late for redirecting to %s, already answered\n", msg->string_arg); @@ -1024,8 +1042,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi } else { switch_set_string(ref_to, msg->string_arg); } - + switch_mutex_lock(tech_pvt->sofia_mutex); nua_refer(tech_pvt->nh, SIPTAG_REFER_TO_STR(ref_to), SIPTAG_REFERRED_BY_STR(tech_pvt->contact_url), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); } break; @@ -1082,9 +1101,11 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Overlap Dial with %d %s\n", code, reason); + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, code, su_strdup(tech_pvt->nh->nh_home, 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_mutex_unlock(tech_pvt->sofia_mutex); if (!switch_channel_test_flag(channel, CF_ANSWERED)) { switch_set_flag_locked(tech_pvt, TFLAG_BYE); } @@ -1104,12 +1125,16 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi sofia_glue_tech_patch_sdp(tech_pvt); sofia_glue_tech_proxy_remote_addr(tech_pvt); } + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, code, su_strdup(tech_pvt->nh->nh_home, reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); } else { + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, code, su_strdup(tech_pvt->nh->nh_home, reason), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); } if (!switch_channel_test_flag(channel, CF_ANSWERED) && code >= 300) { switch_set_flag_locked(tech_pvt, TFLAG_BYE); @@ -1121,7 +1146,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi case SWITCH_MESSAGE_INDICATE_RINGING: if (!switch_channel_test_flag(channel, CF_RING_READY) && !switch_channel_test_flag(channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(channel, CF_ANSWERED)) { + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, SIP_180_RINGING, SIPTAG_CONTACT_STR(tech_pvt->reply_contact), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); switch_channel_mark_ring_ready(channel); } break; @@ -1161,7 +1188,9 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi sofia_glue_tech_prepare_codecs(tech_pvt); if (sofia_glue_tech_media(tech_pvt, r_sdp) != SWITCH_STATUS_SUCCESS) { switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "CODEC NEGOTIATION ERROR"); + //switch_mutex_lock(tech_pvt->sofia_mutex); //nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); + //switch_mutex_unlock(tech_pvt->sofia_mutex); status = SWITCH_STATUS_FALSE; goto end; } @@ -1190,6 +1219,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi switch_channel_set_variable(channel, "sip_nat_detected", "true"); } + switch_mutex_lock(tech_pvt->sofia_mutex); nua_respond(tech_pvt->nh, SIP_183_SESSION_PROGRESS, NUTAG_AUTOANSWER(0), @@ -1199,6 +1229,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi SOATAG_ORDERED_USER(1), SOATAG_ADDRESS(tech_pvt->adv_sdp_audio_ip), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_AUDIO_AUX("cn telephone-event"), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); } } break; @@ -1225,11 +1256,13 @@ static switch_status_t sofia_receive_event(switch_core_session_t *session, switc } if (tech_pvt->hash_key) { + switch_mutex_lock(tech_pvt->sofia_mutex); msg_nh = nua_handle(tech_pvt->profile->nua, NULL, SIPTAG_FROM_STR(tech_pvt->chat_from), NUTAG_URL(tech_pvt->chat_to), SIPTAG_TO_STR(tech_pvt->chat_to), SIPTAG_CONTACT_STR(tech_pvt->profile->url), TAG_END()); nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private); nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END()); + switch_mutex_unlock(tech_pvt->sofia_mutex); } return SWITCH_STATUS_SUCCESS; @@ -1946,6 +1979,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session goto error; } switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(nsession)); + switch_mutex_init(&tech_pvt->sofia_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(nsession)); data = switch_core_session_strdup(nsession, outbound_profile->destination_number); if ((dest_to = strchr(data, '^'))) { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 8572d357d9..39a37d78a1 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -467,6 +467,7 @@ struct private_object { unsigned long rm_rate; switch_payload_t pt; switch_mutex_t *flag_mutex; + switch_mutex_t *sofia_mutex; switch_payload_t te; switch_payload_t bte; switch_payload_t cng_pt; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 5f68ba6d1e..b8935e5def 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -180,6 +180,7 @@ void sofia_event_callback(nua_event_t event, } else if (!switch_strlen_zero(sofia_private->uuid)) { if ((session = switch_core_session_locate(sofia_private->uuid))) { tech_pvt = switch_core_session_get_private(session); + switch_assert(tech_pvt); channel = switch_core_session_get_channel(tech_pvt->session); if (!tech_pvt->call_id && sip && sip->sip_call_id && sip->sip_call_id->i_id) { tech_pvt->call_id = switch_core_session_strdup(session, sip->sip_call_id->i_id); @@ -196,7 +197,7 @@ void sofia_event_callback(nua_event_t event, } if (session) { - switch_core_session_signal_lock(session); + switch_mutex_lock(tech_pvt->sofia_mutex); if (channel && switch_channel_get_state(channel) >= CS_HANGUP) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already hungup.\n"); @@ -353,7 +354,7 @@ void sofia_event_callback(nua_event_t event, } if (session) { - switch_core_session_signal_unlock(session); + switch_mutex_unlock(tech_pvt->sofia_mutex); switch_core_session_rwunlock(session); } } @@ -3486,6 +3487,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); + switch_mutex_init(&tech_pvt->sofia_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip); tech_pvt->remote_port = network_port; diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 49ef74e6e8..397133131e 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -1702,9 +1702,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f const char *var; switch_assert(tech_pvt != NULL); - - switch_core_session_signal_lock(tech_pvt->session); - + switch_mutex_lock(tech_pvt->sofia_mutex); if ((var = switch_channel_get_variable(tech_pvt->channel, SOFIA_SECURE_MEDIA_VARIABLE)) && switch_true(var)) { switch_set_flag_locked(tech_pvt, TFLAG_SECURE); @@ -2027,7 +2025,7 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f end: - switch_core_session_signal_unlock(tech_pvt->session); + switch_mutex_unlock(tech_pvt->sofia_mutex); return status; diff --git a/src/switch_channel.c b/src/switch_channel.c index b0be0ae7ca..3a210a4674 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -390,7 +390,9 @@ SWITCH_DECLARE(void) switch_channel_uninit(switch_channel_t *channel) { switch_channel_flush_dtmf(channel); switch_core_hash_destroy(&channel->private_hash); + switch_mutex_lock(channel->profile_mutex); switch_event_destroy(&channel->variables); + switch_mutex_unlock(channel->profile_mutex); } SWITCH_DECLARE(switch_status_t) switch_channel_init(switch_channel_t *channel, switch_core_session_t *session, switch_channel_state_t state, @@ -562,7 +564,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable(switch_channel_t *ch { switch_assert(channel != NULL); - if (!switch_strlen_zero(varname)) { + if (channel->variables && !switch_strlen_zero(varname)) { switch_mutex_lock(channel->profile_mutex); switch_event_del_header(channel->variables, varname); if (!switch_strlen_zero(value)) { @@ -584,7 +586,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_printf(switch_channe va_list ap; switch_assert(channel != NULL); - if (!switch_strlen_zero(varname)) { + if (channel->variables && !switch_strlen_zero(varname)) { switch_mutex_lock(channel->profile_mutex); switch_event_del_header(channel->variables, varname); diff --git a/src/switch_core_rwlock.c b/src/switch_core_rwlock.c index 2e74ecc897..11db1057b9 100644 --- a/src/switch_core_rwlock.c +++ b/src/switch_core_rwlock.c @@ -35,15 +35,6 @@ #include #include "private/switch_core_pvt.h" -SWITCH_DECLARE(switch_status_t) switch_core_session_signal_lock(switch_core_session_t *session) -{ - return switch_mutex_lock(session->signal_mutex); -} - -SWITCH_DECLARE(switch_status_t) switch_core_session_signal_unlock(switch_core_session_t *session) -{ - return switch_mutex_unlock(session->signal_mutex); -} #ifdef SWITCH_DEBUG_RWLOCKS SWITCH_DECLARE(switch_status_t) switch_core_session_perform_read_lock(switch_core_session_t *session, const char *file, const char *func, int line) diff --git a/src/switch_core_session.c b/src/switch_core_session.c index e9d21c244f..46ab46dadd 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -57,9 +57,10 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_locate(const char *u if ((session = switch_core_hash_find(session_manager.session_table, uuid_str))) { /* Acquire a read lock on the session */ #ifdef SWITCH_DEBUG_RWLOCKS - if (switch_core_session_perform_read_lock(session, file, func, line) != SWITCH_STATUS_SUCCESS) { + if (switch_channel_get_state(session->channel) >= CS_HANGUP || + switch_core_session_perform_read_lock(session, file, func, line) != SWITCH_STATUS_SUCCESS) { #else - if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) { + if (switch_channel_get_state(session->channel) >= CS_HANGUP || switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) { #endif /* not available, forget it */ session = NULL; @@ -418,8 +419,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_ 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); } @@ -433,9 +432,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_receive_message(switch_core_ } switch_core_session_kill_channel(session, SWITCH_SIG_BREAK); - - switch_core_session_signal_unlock(session); - switch_core_session_rwunlock(session); return status; @@ -988,7 +984,6 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool); switch_mutex_init(&session->resample_mutex, SWITCH_MUTEX_NESTED, session->pool); - switch_mutex_init(&session->signal_mutex, SWITCH_MUTEX_NESTED, session->pool); switch_thread_rwlock_create(&session->bug_rwlock, session->pool); switch_thread_cond_create(&session->cond, session->pool); switch_thread_rwlock_create(&session->rwlock, session->pool); diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index 6b5f2fc423..0bf7bd9cc5 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -396,9 +396,8 @@ 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); hook_var = switch_channel_get_variable(session->channel, SWITCH_API_HANGUP_HOOK_VARIABLE); @@ -418,19 +417,13 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) } goto done; 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_ROUTING: /* Look for a dialplan and find something to do */ - switch_core_session_signal_lock(session); STATE_MACRO(routing, "ROUTING"); - switch_core_session_signal_unlock(session); break; case CS_RESET: /* Reset */ - switch_core_session_signal_lock(session); STATE_MACRO(reset, "RESET"); - switch_core_session_signal_unlock(session); break; /* These other states are intended for prolonged durations so we do not signal lock for them */ case CS_EXECUTE: /* Execute an Operation */