[Freeswitch-svn] [commit] r2708 - in freeswitch/trunk/src: . mod/endpoints/mod_sofia mod/languages/mod_spidermonkey mod/timers/mod_threadtimer

Freeswitch SVN anthm at freeswitch.org
Fri Sep 15 17:43:19 EDT 2006


Author: anthm
Date: Fri Sep 15 17:43:18 2006
New Revision: 2708

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/Makefile
   freeswitch/trunk/src/mod/timers/mod_threadtimer/mod_threadtimer.c
   freeswitch/trunk/src/switch_channel.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_utils.c

Log:
optimizations and disable the conditional thing till we see why it dies at 100cps X 800 calls

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Fri Sep 15 17:43:18 2006
@@ -739,7 +739,6 @@
 					  tech_pvt->read_codec.implementation->ianacode,
 					  tech_pvt->read_codec.implementation->microseconds_per_frame / 1000);
 
-
 	tech_pvt->rtp_session = switch_rtp_new(tech_pvt->local_sdp_audio_ip,
 										   tech_pvt->local_sdp_audio_port,
 										   tech_pvt->remote_sdp_audio_ip,
@@ -1360,80 +1359,82 @@
 	case nua_callstate_calling:
 		break;
 	case nua_callstate_proceeding:
-		if (session && r_sdp) {
-			sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
-			sdp_session_t *sdp;
-			uint8_t match = 0;
+		if (channel) {
+			if (r_sdp) {
+				sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
+				sdp_session_t *sdp;
+				uint8_t match = 0;
 
-			if (tech_pvt->num_codecs) {
-				if ((sdp = sdp_session(parser))) {
-					match = negotiate_sdp(session, sdp);
+				if (tech_pvt->num_codecs) {
+					if ((sdp = sdp_session(parser))) {
+						match = negotiate_sdp(session, sdp);
+					}
 				}
-			}
 
-			if (parser) {
-				sdp_parser_free(parser);
-			}
+				if (parser) {
+					sdp_parser_free(parser);
+				}
 
 
-			if (match) {
-				tech_choose_port(tech_pvt);
-                activate_rtp(tech_pvt);
-				switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
-                switch_channel_pre_answer(channel);
-				return;
+				if (match) {
+					tech_choose_port(tech_pvt);
+					activate_rtp(tech_pvt);
+					switch_channel_set_variable(channel, "endpoint_disposition", "EARLY MEDIA");
+					switch_channel_pre_answer(channel);
+					return;
+				}
+				switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
+				nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
+							//SIPTAG_CONTACT(tech_pvt->contact), 
+							TAG_END());
 			}
 		}
-		if (channel) {
-			switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
-		}
-		nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
-					//SIPTAG_CONTACT(tech_pvt->contact), 
-					TAG_END());
+
 		break;
 	case nua_callstate_completing:
 		nua_ack(nh, TAG_END());
 		break;
 	case nua_callstate_received: 
-		if (session && r_sdp) {
-			sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
-			sdp_session_t *sdp;
-			uint8_t match = 0;
+		if (channel) {
+			if (r_sdp) {
+				sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
+				sdp_session_t *sdp;
+				uint8_t match = 0;
 
 
 
-			if (tech_pvt->num_codecs) {
-				if ((sdp = sdp_session(parser))) {
-					match = negotiate_sdp(session, sdp);
+				if (tech_pvt->num_codecs) {
+					if ((sdp = sdp_session(parser))) {
+						match = negotiate_sdp(session, sdp);
+					}
 				}
-			}
 
-			if (parser) {
-				sdp_parser_free(parser);
-			}
+				if (parser) {
+					sdp_parser_free(parser);
+				}
 
 
-			if (match) {
-				switch_channel_set_variable(channel, "endpoint_disposition", "RECEIVED");
-				switch_channel_set_state(channel, CS_INIT);
-				switch_set_flag_locked(tech_pvt, TFLAG_READY);
-				switch_core_session_thread_launch(session);
-				return;
+				if (match) {
+					switch_channel_set_variable(channel, "endpoint_disposition", "RECEIVED");
+					switch_channel_set_state(channel, CS_INIT);
+					switch_set_flag_locked(tech_pvt, TFLAG_READY);
+					switch_core_session_thread_launch(session);
+					return;
+				}
+				switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
+				nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
+							//SIPTAG_CONTACT(tech_pvt->contact), 
+							TAG_END());
 			}
 		}
-		if (channel) {
-			switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
-		}
-		nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
-					//SIPTAG_CONTACT(tech_pvt->contact), 
-					TAG_END());
+
 		break;		
 	case nua_callstate_early:
 		break;
 	case nua_callstate_completed:
 		break;
 	case nua_callstate_ready:
-		if (session) {
+		if (channel) {
 			if (r_sdp) {
 				sdp_parser_t *parser = sdp_parse(tech_pvt->home, r_sdp, (int)strlen(r_sdp), 0);
 				sdp_session_t *sdp;
@@ -1458,18 +1459,19 @@
 					switch_channel_answer(channel);
 					return;
 				}
+
+				switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
+				nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
+							//SIPTAG_CONTACT(tech_pvt->contact), 
+							TAG_END());
 			} else if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
 				switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
 				switch_channel_answer(channel);
 				return;
-			}
+			} //else probably an ack
+
 		}
-		if (channel) {
-			switch_channel_set_variable(channel, "endpoint_disposition", "NO CODECS");
-		}
-		nua_respond(nh, SIP_488_NOT_ACCEPTABLE, 
-					//SIPTAG_CONTACT(tech_pvt->contact), 
-					TAG_END());
+
 		break;
 	case nua_callstate_terminating:
 		break;

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/Makefile	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/Makefile	Fri Sep 15 17:43:18 2006
@@ -69,7 +69,7 @@
 
 depends:
 	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) mozilla.tar.gz --prefix=$(PREFIX)
-	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install curl-7.15.2.tar.gz --prefix=$(PREFIX)
+	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install curl-7.15.2.tar.gz --prefix=$(PREFIX) --without-libidn
 	MAKE=$(MAKE) $(BASE)/build/buildlib.sh $(BASE) install libetpan-0.45.tar.gz --prefix=$(PREFIX)
 
 $(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c

Modified: freeswitch/trunk/src/mod/timers/mod_threadtimer/mod_threadtimer.c
==============================================================================
--- freeswitch/trunk/src/mod/timers/mod_threadtimer/mod_threadtimer.c	(original)
+++ freeswitch/trunk/src/mod/timers/mod_threadtimer/mod_threadtimer.c	Fri Sep 15 17:43:18 2006
@@ -45,31 +45,27 @@
 #define MAX_ELEMENTS 1000
 
 struct timer_private {
-	uint64_t tick;
-	uint64_t reference;
-	uint32_t interval;
-	//switch_mutex_t *mutex;
-	struct timer_private *next;
+    uint32_t reference;
 };
-
 typedef struct timer_private timer_private_t;
 
-struct timer_head {
-	timer_private_t *private_info;
-	switch_mutex_t *mutex;
+struct timer_matrix {
+	uint64_t tick;
+	uint32_t count;
 };
-typedef struct timer_head timer_head_t;
+typedef struct timer_matrix timer_matrix_t;
 
-static timer_head_t *TIMER_MATRIX[MAX_ELEMENTS+1];
+static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1];
 
 #define IDLE_SPEED 100
 
+
 static inline void set_timer(void)
 {
 	uint32_t index = 0, min = IDLE_SPEED;
 
 	for(index = 0; index < MAX_ELEMENTS; index++) {
-		if (TIMER_MATRIX[index] && TIMER_MATRIX[index]->private_info) {
+		if (TIMER_MATRIX[index].count) {
 			if (min > index) {
 				min = index;
 			}
@@ -83,27 +79,13 @@
 static inline switch_status_t timer_init(switch_timer_t *timer)
 {
 	timer_private_t *private_info;
-	timer_head_t *head;
 
-
 	if ((private_info = switch_core_alloc(timer->memory_pool, sizeof(*private_info)))) {
+		switch_mutex_lock(globals.mutex);
+		TIMER_MATRIX[timer->interval].count++;
+		switch_mutex_unlock(globals.mutex);
 		timer->private_info = private_info;
-		if (!TIMER_MATRIX[timer->interval]) {
-			if (!(TIMER_MATRIX[timer->interval] = switch_core_alloc(module_pool, sizeof(timer_head_t)))) {
-				return SWITCH_STATUS_MEMERR;
-			}
-			switch_mutex_init(&TIMER_MATRIX[timer->interval]->mutex, SWITCH_MUTEX_NESTED, module_pool);
-		}
-
-		head = TIMER_MATRIX[timer->interval];
-
-		//switch_mutex_init(&private_info->mutex, SWITCH_MUTEX_NESTED, timer->memory_pool);
-		private_info->interval = timer->interval;
-
-		switch_mutex_lock(head->mutex);
-		private_info->next = head->private_info;
-		head->private_info = private_info;
-		switch_mutex_unlock(head->mutex);
+		private_info->reference = TIMER_MATRIX[timer->interval].tick;
 		set_timer();
 
 		return SWITCH_STATUS_SUCCESS;
@@ -116,9 +98,7 @@
 {
 	timer_private_t *private_info = timer->private_info;
 
-	//switch_mutex_lock(private_info->mutex);
-	private_info->reference += private_info->interval;
-	//switch_mutex_unlock(private_info->mutex);
+	private_info->reference += timer->interval;
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -128,9 +108,8 @@
 {
 	timer_private_t *private_info = timer->private_info;
 
-
 	timer_step(timer);
-	while (private_info->tick < private_info->reference) {
+	while (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
 		switch_yield(1000);
 	}
 	timer->samplecount += timer->samples;
@@ -144,14 +123,12 @@
 	timer_private_t *private_info = timer->private_info;
 	switch_status_t status;
 
-	//switch_mutex_lock(private_info->mutex);
-	if (private_info->tick < private_info->reference) {
+	if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
 		status = SWITCH_STATUS_FALSE;
 	} else {
-		private_info->reference += private_info->interval;
+		private_info->reference += timer->interval;
 		status = SWITCH_STATUS_SUCCESS;
 	}
-	//switch_mutex_unlock(private_info->mutex);
 
 	return status;
 }
@@ -159,26 +136,9 @@
 
 static inline switch_status_t timer_destroy(switch_timer_t *timer)
 {
-	timer_private_t *private_info = timer->private_info;
-	timer_head_t *head;
-	timer_private_t *ptr, *last = NULL;
-
-	head = TIMER_MATRIX[timer->interval];
-	assert(head != NULL);
-	assert(private_info != NULL);
-
-	switch_mutex_lock(head->mutex);
-	for(ptr = head->private_info; ptr; ptr = ptr->next) {
-		if (ptr == private_info) {
-			if (last) {
-				last->next = private_info->next;
-			} else {
-				head->private_info = private_info->next;
-			}
-		}
-		last = ptr;
-	}
-	switch_mutex_unlock(head->mutex);
+	switch_mutex_lock(globals.mutex);
+	TIMER_MATRIX[timer->interval].count--;
+	switch_mutex_unlock(globals.mutex);
 	set_timer();
 	timer->private_info = NULL;
 	return SWITCH_STATUS_SUCCESS;
@@ -223,7 +183,6 @@
 {
 	switch_time_t reference = switch_time_now();
 	uint32_t current_ms = 0;
-	timer_private_t *ptr;
 	uint32_t x;
 	
 	memset(&globals, 0, sizeof(globals));
@@ -235,7 +194,7 @@
 
 	while(globals.RUNNING == 1) {
 		reference += globals.timer_microseconds;
-		//printf("TEST %d\n", globals.timer_microseconds);
+
 		while (switch_time_now() < reference) {
 			//switch_yield((reference - now) - 1000);
 			switch_yield(globals.timer_microseconds >> 1);
@@ -251,14 +210,8 @@
 			
 			index = (current_ms % i == 0) ? i : 0; 
 
-			if (TIMER_MATRIX[index] && TIMER_MATRIX[index]->private_info) {
-				switch_mutex_lock(TIMER_MATRIX[index]->mutex);
-				for (ptr = TIMER_MATRIX[index]->private_info; ptr; ptr = ptr->next) {
-					//switch_mutex_lock(ptr->mutex);
-					ptr->tick += ptr->interval;
-					//switch_mutex_unlock(ptr->mutex);
-				}
-				switch_mutex_unlock(TIMER_MATRIX[index]->mutex);
+			if (TIMER_MATRIX[index].count) {
+				TIMER_MATRIX[index].tick += index;
 			}
 		}
 

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Fri Sep 15 17:43:18 2006
@@ -589,10 +589,11 @@
 				switch_event_fire(&event);
 			}
 		}
-		
+		/*		
 		if (state < CS_DONE) {
 			switch_core_session_signal_state_change(channel->session);
 		}
+		*/
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_WARNING, "%s Invalid State Change %s -> %s\n", 
 						  channel->name,
@@ -875,7 +876,7 @@
 		}
 
 		switch_core_session_kill_channel(channel->session, SWITCH_SIG_KILL);
-		switch_core_session_signal_state_change(channel->session);
+		//switch_core_session_signal_state_change(channel->session);
 	}
 	return channel->state;
 }

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Fri Sep 15 17:43:18 2006
@@ -90,8 +90,8 @@
 	switch_audio_resampler_t *read_resampler;
 	switch_audio_resampler_t *write_resampler;
 
-	switch_mutex_t *mutex;
-	switch_thread_cond_t *cond;
+	//switch_mutex_t *mutex;
+	//switch_thread_cond_t *cond;
 
 	switch_thread_rwlock_t *rwlock;
 
@@ -2489,11 +2489,13 @@
 
 SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session_t *session)
 {
-	/* If trylock fails the signal is already awake so we need'nt bother */
+	return;
+	/* If trylock fails the signal is already awake so we needn't bother 
 	if (switch_mutex_trylock(session->mutex) == SWITCH_STATUS_SUCCESS) {
 		switch_thread_cond_signal(session->cond);
 		switch_mutex_unlock(session->mutex);
 	} 
+	*/
 }
 
 SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session_t *session)
@@ -2605,7 +2607,7 @@
 	driver_state_handler = endpoint_interface->state_handler;
 	assert(driver_state_handler != NULL);
 
-	switch_mutex_lock(session->mutex);
+	//switch_mutex_lock(session->mutex);
 
 	while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
 		if (state != laststate) {
@@ -2884,17 +2886,26 @@
 			laststate = midstate;
 		}
 		
-		if (state < CS_DONE && midstate == switch_channel_get_state(session->channel)) {
-			switch_thread_cond_wait(session->cond, session->mutex);
-		} 
+		if (state >= CS_HANGUP) {
+			goto done;
+		}
+
+		if (midstate == switch_channel_get_state(session->channel)) {
+			//switch_thread_cond_wait(session->cond, session->mutex);
+			switch_yield(10000);
+		} else {
+			switch_yield(1000);
+		}
+
 	}
  done:
+	//switch_mutex_unlock(session->mutex);
 
 #ifdef CRASH_PROT
 	apr_hash_set(runtime.stack_table, &thread_id, sizeof(thread_id), NULL);
 #endif
 	session->thread_running = 0;
-	switch_mutex_unlock(session->mutex);
+
 }
 
 SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session_t **session)
@@ -3140,9 +3151,9 @@
 	session->enc_read_frame.data = session->enc_read_buf;
 	session->enc_read_frame.buflen = sizeof(session->enc_read_buf);
 
-	switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
+	//switch_mutex_init(&session->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_cond_create(&session->cond, session->pool);
 	switch_thread_rwlock_create(&session->rwlock, session->pool);
 
 	switch_mutex_lock(runtime.session_table_mutex);

Modified: freeswitch/trunk/src/switch_utils.c
==============================================================================
--- freeswitch/trunk/src/switch_utils.c	(original)
+++ freeswitch/trunk/src/switch_utils.c	Fri Sep 15 17:43:18 2006
@@ -204,9 +204,7 @@
 {
 	int nsds = 0;
 
-	if (switch_poll(poll, 1, &nsds, ms) != SWITCH_STATUS_SUCCESS) {
-		return -1;
-	}
+	switch_poll(poll, 1, &nsds, ms);
 
 	return nsds;
 }



More information about the Freeswitch-svn mailing list