[Freeswitch-svn] [commit] r7984 - freeswitch/trunk/src/mod/endpoints/mod_iax

Freeswitch SVN anthm at freeswitch.org
Mon Mar 31 11:31:06 EDT 2008


Author: anthm
Date: Mon Mar 31 11:31:05 2008
New Revision: 7984

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c

Log:
add a bunch of locking to mod_iax, if it deadlocks nobody will be suprised

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c	Mon Mar 31 11:31:05 2008
@@ -505,6 +505,7 @@
 		switch_core_codec_destroy(&tech_pvt->write_codec);
 	}
 
+	switch_mutex_lock(globals.mutex);
 	if (tech_pvt->iax_session) {
 		if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
 			iax_hangup(tech_pvt->iax_session, "Hangup");
@@ -514,7 +515,6 @@
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(switch_core_session_get_channel(session)));
-	switch_mutex_lock(globals.mutex);
 	globals.calls--;
 	if (globals.calls < 0) {
 		globals.calls = 0;
@@ -576,7 +576,9 @@
 	private_t *tech_pvt = switch_core_session_get_private(session);
 	switch_assert(tech_pvt != NULL);
 	if (tech_pvt->iax_session) {
+		switch_mutex_lock(globals.mutex);
 		iax_send_dtmf(tech_pvt->iax_session, dtmf->digit);
+		switch_mutex_unlock(globals.mutex);
 	}
 
 	return SWITCH_STATUS_SUCCESS;
@@ -674,7 +676,9 @@
 	switch_assert(tech_pvt != NULL);
 
 	if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
+		switch_mutex_lock(globals.mutex);
 		iax_answer(tech_pvt->iax_session);
+		switch_mutex_unlock(globals.mutex);
 	}
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -689,8 +693,10 @@
 	case SWITCH_MESSAGE_INDICATE_RESPOND:
 		{
 			if (tech_pvt->iax_session) {
+				switch_mutex_lock(globals.mutex);
 				iax_reject(tech_pvt->iax_session, msg->string_arg ? msg->string_arg : "Call Rejected");
 				switch_set_flag(tech_pvt, TFLAG_HANGUP);
+				switch_mutex_unlock(globals.mutex);
 			}
 		}
 		break;
@@ -745,7 +751,11 @@
 			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 		}
 
-		if ((tech_pvt->iax_session = iax_session_new()) == 0) {
+		switch_mutex_lock(globals.mutex);
+		tech_pvt->iax_session = iax_session_new();
+		switch_mutex_unlock(globals.mutex);
+
+		if (!tech_pvt->iax_session) {
 			switch_core_session_destroy(new_session);
 			return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 		}
@@ -955,6 +965,7 @@
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event %d [%s]!\n", iaxevent->etype, IAXNAMES[iaxevent->etype]);
 			}
 
+			switch_mutex_lock(globals.mutex);
 			switch (iaxevent->etype) {
 			case IAX_EVENT_REGACK:
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Registration completed successfully.\n");
@@ -1129,7 +1140,7 @@
 				break;
 			}
 			iax_event_free(iaxevent);
-
+			switch_mutex_unlock(globals.mutex);			
 			if (tech_pvt && tech_pvt->session) {
 				switch_core_session_signal_unlock(tech_pvt->session);
 			}



More information about the Freeswitch-svn mailing list