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

Freeswitch SVN anthm at freeswitch.org
Wed Sep 13 15:02:23 EDT 2006


Author: anthm
Date: Wed Sep 13 15:02:22 2006
New Revision: 2687

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

Log:
twiax

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	Wed Sep 13 15:02:22 2006
@@ -76,6 +76,8 @@
 	int codec_rates_last;
 	unsigned int flags;
 	int fd;
+	int calls;
+	switch_mutex_t *mutex;
 } globals;
 
 struct private_object {
@@ -468,6 +470,9 @@
 
 	/* Move Channel's State Machine to RING */
 	switch_channel_set_state(channel, CS_RING);
+	switch_mutex_lock(globals.mutex);
+	globals.calls++;
+	switch_mutex_unlock(globals.mutex);
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -538,7 +543,13 @@
 	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel));
-
+	switch_mutex_lock(globals.mutex);
+	globals.calls--;
+	if (globals.calls < 0) {
+		globals.calls = 0;
+	}
+	switch_mutex_unlock(globals.mutex);
+		
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -826,6 +837,7 @@
 		return SWITCH_STATUS_TERM;
 	}
 
+	
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = &channel_module_interface;
 
@@ -849,7 +861,7 @@
 	switch_xml_t cfg, xml, settings, param;
 
 	memset(&globals, 0, sizeof(globals));
-
+	switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
 	if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
 		return SWITCH_STATUS_TERM;
@@ -929,15 +941,27 @@
 
 	for (;;) {
 
+
 		if (running == -1) {
 			break;
 		}
 
 		/* Wait for an event. */
-		if ((iaxevent = iax_get_event(-1)) == NULL) {
-			//switch_yield(100);
-			//continue;
-			break;
+		if ((iaxevent = iax_get_event(0)) == NULL) {
+			int waitlen = 0;
+			
+			if (globals.calls == 0) {
+				waitlen = 10000;
+			} else if (globals.calls == 1) {
+				waitlen = 1000;
+			} else if (globals.calls < 10) {
+				waitlen = 100;
+			} else {
+				waitlen = 10;
+			}
+
+			switch_yield(waitlen);
+			continue;
 		} else {
 			struct private_object *tech_pvt = iax_get_private(iaxevent->session);
 



More information about the Freeswitch-svn mailing list