[Freeswitch-svn] [commit] r10136 - in freeswitch/trunk/src: . include mod/applications/mod_rss mod/languages/mod_managed mod/languages/mod_managed/managed mod/languages/mod_spidermonkey_teletone

Freeswitch SVN anthm at freeswitch.org
Thu Oct 23 19:48:12 EDT 2008


Author: anthm
Date: Thu Oct 23 19:48:11 2008
New Revision: 10136

Modified:
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
   freeswitch/trunk/src/mod/languages/mod_managed/freeswitch_wrap.cxx
   freeswitch/trunk/src/mod/languages/mod_managed/managed/swig.cs
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_ivr_play_say.c

Log:
simplify switch_core_service_session to protect against a race condition

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Thu Oct 23 19:48:11 2008
@@ -740,18 +740,15 @@
 
 /*! 
   \brief Signal a thread using a thread session to terminate
-  \param thread_session the thread_session to indicate to
+  \param session the session to indicate to
 */
-SWITCH_DECLARE(void) switch_core_thread_session_end(_In_ switch_core_thread_session_t *thread_session);
+SWITCH_DECLARE(void) switch_core_thread_session_end(_In_ switch_core_session_t *session);
 
 /*! 
   \brief Launch a service thread on a session to drop inbound data
   \param session the session the launch thread on
-  \param stream_id which logical media channel to use
-  \param thread_session the thread_session to use
 */
-SWITCH_DECLARE(void) switch_core_service_session(_In_ switch_core_session_t *session,
-												 _In_ switch_core_thread_session_t *thread_session, _In_ int stream_id);
+SWITCH_DECLARE(void) switch_core_service_session(_In_ switch_core_session_t *session);
 
 /*! 
   \brief Request an outgoing session spawned from an existing session using a desired endpoing module

Modified: freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c	Thu Oct 23 19:48:11 2008
@@ -169,7 +169,6 @@
 	char *timer_name = NULL;
 	switch_speech_handle_t sh;
 	switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
-	switch_core_thread_session_t thread_session;
 	switch_timer_t timer = { 0 }, *timerp = NULL;
 	uint32_t last;
 	char *mydata = NULL;
@@ -293,7 +292,7 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setup timer success %u bytes per %d ms!\n", (rate / 50) * 2, interval);
 
 		/* start a thread to absorb incoming audio */
-		switch_core_service_session(session, &thread_session, 0);
+		switch_core_service_session(session);
 		timerp = &timer;
 	}
 
@@ -615,7 +614,7 @@
 
 	if (timerp) {
 		/* End the audio absorbing thread */
-		switch_core_thread_session_end(&thread_session);
+		switch_core_thread_session_end(session);
 		switch_core_timer_destroy(&timer);
 	}
 

Modified: freeswitch/trunk/src/mod/languages/mod_managed/freeswitch_wrap.cxx
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_managed/freeswitch_wrap.cxx	(original)
+++ freeswitch/trunk/src/mod/languages/mod_managed/freeswitch_wrap.cxx	Thu Oct 23 19:48:11 2008
@@ -5441,22 +5441,18 @@
 
 
 SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_thread_session_end(void * jarg1) {
-  switch_core_thread_session_t *arg1 = (switch_core_thread_session_t *) 0 ;
+  switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
   
-  arg1 = (switch_core_thread_session_t *)jarg1; 
+  arg1 = (switch_core_session_t *)jarg1; 
   switch_core_thread_session_end(arg1);
 }
 
 
-SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_service_session(void * jarg1, void * jarg2, int jarg3) {
+SWIGEXPORT void SWIGSTDCALL CSharp_switch_core_service_session(void * jarg1) {
   switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
-  switch_core_thread_session_t *arg2 = (switch_core_thread_session_t *) 0 ;
-  int arg3 ;
   
   arg1 = (switch_core_session_t *)jarg1; 
-  arg2 = (switch_core_thread_session_t *)jarg2; 
-  arg3 = (int)jarg3; 
-  switch_core_service_session(arg1,arg2,arg3);
+  switch_core_service_session(arg1);
 }
 
 

Modified: freeswitch/trunk/src/mod/languages/mod_managed/managed/swig.cs
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_managed/managed/swig.cs	(original)
+++ freeswitch/trunk/src/mod/languages/mod_managed/managed/swig.cs	Thu Oct 23 19:48:11 2008
@@ -1262,12 +1262,12 @@
     freeswitchPINVOKE.switch_core_session_launch_thread(SWIGTYPE_p_switch_core_session.getCPtr(session), SWIGTYPE_p_f_p_switch_thread_t_p_void__p_void.getCPtr(func), SWIGTYPE_p_void.getCPtr(obj));
   }
 
-  public static void switch_core_thread_session_end(switch_core_thread_session thread_session) {
-    freeswitchPINVOKE.switch_core_thread_session_end(switch_core_thread_session.getCPtr(thread_session));
+  public static void switch_core_thread_session_end(SWIGTYPE_p_switch_core_session session) {
+    freeswitchPINVOKE.switch_core_thread_session_end(SWIGTYPE_p_switch_core_session.getCPtr(session));
   }
 
-  public static void switch_core_service_session(SWIGTYPE_p_switch_core_session session, switch_core_thread_session thread_session, int stream_id) {
-    freeswitchPINVOKE.switch_core_service_session(SWIGTYPE_p_switch_core_session.getCPtr(session), switch_core_thread_session.getCPtr(thread_session), stream_id);
+  public static void switch_core_service_session(SWIGTYPE_p_switch_core_session session) {
+    freeswitchPINVOKE.switch_core_service_session(SWIGTYPE_p_switch_core_session.getCPtr(session));
   }
 
   public static switch_call_cause_t switch_core_session_outgoing_channel(SWIGTYPE_p_switch_core_session session, switch_event var_event, string endpoint_name, switch_caller_profile caller_profile, SWIGTYPE_p_p_switch_core_session new_session, SWIGTYPE_p_p_apr_pool_t pool, uint flags) {
@@ -5449,7 +5449,7 @@
   public static extern void switch_core_thread_session_end(HandleRef jarg1);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_service_session")]
-  public static extern void switch_core_service_session(HandleRef jarg1, HandleRef jarg2, int jarg3);
+  public static extern void switch_core_service_session(HandleRef jarg1);
 
   [DllImport("mod_managed", EntryPoint="CSharp_switch_core_session_outgoing_channel")]
   public static extern int switch_core_session_outgoing_channel(HandleRef jarg1, HandleRef jarg2, string jarg3, HandleRef jarg4, HandleRef jarg5, HandleRef jarg6, uint jarg7);

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c	Thu Oct 23 19:48:11 2008
@@ -209,7 +209,6 @@
 		switch_frame_t write_frame = { 0 };
 		unsigned char *fdata[1024];
 		switch_frame_t *read_frame;
-		switch_core_thread_session_t thread_session = { 0 };
 		switch_channel_t *channel;
 
 		if (argc > 1) {
@@ -237,7 +236,7 @@
 		channel = switch_core_session_get_channel(session);
 
 		if (tto->timer) {
-			switch_core_service_session(session, &thread_session, 0);
+			switch_core_service_session(session);
 		}
 
 		if (loops) {
@@ -291,7 +290,7 @@
 		}
 
 		if (tto->timer) {
-			switch_core_thread_session_end(&thread_session);
+			switch_core_thread_session_end(session);
 		}
 		return JS_TRUE;
 	}

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Thu Oct 23 19:48:11 2008
@@ -271,53 +271,54 @@
 
 static void *switch_core_service_thread(switch_thread_t *thread, void *obj)
 {
-	switch_core_thread_session_t *data = obj;
-	switch_core_session_t *session = data->objs[0];
-	int *stream_id_p = data->objs[1];
+	switch_core_session_t *session = obj;
 	switch_channel_t *channel;
 	switch_frame_t *read_frame;
-	int stream_id = *stream_id_p;
 
 	switch_assert(thread != NULL);
 	switch_assert(session != NULL);
+
+	switch_core_session_read_lock(session);
 	channel = switch_core_session_get_channel(session);
 
 	switch_channel_set_flag(channel, CF_SERVICE);
-	while (data->running > 0) {
-		switch (switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, stream_id)) {
+	while (switch_channel_test_flag(channel, CF_SERVICE)) {
+		switch (switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0)) {
 		case SWITCH_STATUS_SUCCESS:
 		case SWITCH_STATUS_TIMEOUT:
 		case SWITCH_STATUS_BREAK:
 			break;
 		default:
-			data->running = -1;
+			switch_channel_clear_flag(channel, CF_SERVICE);
 			continue;
 		}
 	}
 
-	switch_channel_clear_flag(channel, CF_SERVICE);
-	data->running = 0;
+	switch_core_session_rwunlock(session);
 	return NULL;
 }
 
 /* Either add a timeout here or make damn sure the thread cannot get hung somehow (my preference) */
-SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_thread_session_t *thread_session)
+SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_session_t *session)
 {
-	if (thread_session->running > 0) {
-		thread_session->running = -1;
+	switch_channel_t *channel;
+	switch_assert(session);
 
-		while (thread_session->running) {
-			switch_yield(1000);
-		}
-	}
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel);
+	
+	switch_channel_clear_flag(channel, CF_SERVICE);
 }
 
-SWITCH_DECLARE(void) switch_core_service_session(switch_core_session_t *session, switch_core_thread_session_t *thread_session, int stream_id)
+SWITCH_DECLARE(void) switch_core_service_session(switch_core_session_t *session)
 {
-	thread_session->running = 1;
-	thread_session->objs[0] = session;
-	thread_session->objs[1] = &stream_id;
-	switch_core_session_launch_thread(session, switch_core_service_thread, thread_session);
+	switch_channel_t *channel;
+	switch_assert(session);
+
+	channel = switch_core_session_get_channel(session);
+	switch_assert(channel);
+	
+	switch_core_session_launch_thread(session, switch_core_service_thread, session);
 }
 
 /* This function abstracts the thread creation for modules by allowing you to pass a function ptr and

Modified: freeswitch/trunk/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_play_say.c	(original)
+++ freeswitch/trunk/src/switch_ivr_play_say.c	Thu Oct 23 19:48:11 2008
@@ -729,7 +729,6 @@
 	switch_size_t olen = 0, llen = 0;
 	switch_frame_t write_frame = { 0 };
 	switch_timer_t timer = { 0 };
-	switch_core_thread_session_t thread_session = { 0 };
 	switch_codec_t codec;
 	switch_memory_pool_t *pool = switch_core_session_get_pool(session);
 	char *codec_name;
@@ -963,7 +962,7 @@
 
 	if (timer_name) {
 		/* start a thread to absorb incoming audio */
-		switch_core_service_session(session, &thread_session, 0);
+		switch_core_service_session(session);
 	}
 
 	ilen = samples;
@@ -1230,7 +1229,7 @@
 	}
 	if (timer_name) {
 		/* End the audio absorbing thread */
-		switch_core_thread_session_end(&thread_session);
+		switch_core_thread_session_end(session);
 		switch_core_timer_destroy(&timer);
 	}
 
@@ -1842,7 +1841,6 @@
 	int interval = 0;
 	switch_frame_t write_frame = { 0 };
 	switch_timer_t ltimer, *timer;
-	switch_core_thread_session_t thread_session = { 0 };
 	switch_codec_t lcodec, *codec;
 	switch_memory_pool_t *pool = switch_core_session_get_pool(session);
 	char *codec_name;
@@ -1948,7 +1946,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setup timer success %u bytes per %d ms!\n", sh->samples * 2, interval);
 		}
 		/* start a thread to absorb incoming audio */
-		switch_core_service_session(session, &thread_session, 0);
+		switch_core_service_session(session);
 
 	}
 
@@ -1962,7 +1960,7 @@
 
 	if (timer_name) {
 		/* End the audio absorbing thread */
-		switch_core_thread_session_end(&thread_session);
+		switch_core_thread_session_end(session);
 		if (!cache_obj) {
 			switch_core_timer_destroy(timer);
 		}



More information about the Freeswitch-svn mailing list