[Freeswitch-svn] [commit] r4930 - freeswitch/trunk/src/mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Fri Apr 13 19:19:51 EDT 2007


Author: anthm
Date: Fri Apr 13 19:19:51 2007
New Revision: 4930

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c

Log:
fix shutdown

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 Apr 13 19:19:51 2007
@@ -1002,8 +1002,13 @@
 	switch_core_hash_init(&mod_sofia_globals.gateway_hash, module_pool);
 	switch_mutex_init(&mod_sofia_globals.hash_mutex, SWITCH_MUTEX_NESTED, module_pool);
 
-	config_sofia(0);
+	if (config_sofia(0) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_GENERR;
+	}
 
+	switch_mutex_lock(mod_sofia_globals.mutex);
+	mod_sofia_globals.running = 1;
+	switch_mutex_unlock(mod_sofia_globals.mutex);
 
 	if (switch_event_bind((char *) modname, SWITCH_EVENT_PRESENCE_IN, SWITCH_EVENT_SUBCLASS_ANY, sofia_presence_event_handler, NULL)
 		!= SWITCH_STATUS_SUCCESS) {
@@ -1045,17 +1050,21 @@
 
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
 {
-
+	int sanity = 0;
+	
 	sofia_presence_cancel();
 
 	switch_mutex_lock(mod_sofia_globals.mutex);
 	if (mod_sofia_globals.running == 1) {
-		mod_sofia_globals.running = -1;
+		mod_sofia_globals.running = 0;
 	}
 	switch_mutex_unlock(mod_sofia_globals.mutex);
 
-	while (mod_sofia_globals.running) {
+	while (mod_sofia_globals.threads) {
 		switch_yield(1000);
+		if (++sanity >= 5000) {
+			break;
+		}
 	}
 
 	su_deinit();

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Fri Apr 13 19:19:51 2007
@@ -146,6 +146,7 @@
 	switch_mutex_t *hash_mutex;
 	uint32_t callid;
 	int32_t running;
+	int32_t threads;
 	switch_mutex_t *mutex;
 	char guess_ip[80];
 };

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Fri Apr 13 19:19:51 2007
@@ -240,6 +240,10 @@
 	uint32_t gateway_loops = 0;
 	switch_event_t *s_event;
 
+	switch_mutex_lock(mod_sofia_globals.mutex);
+	mod_sofia_globals.threads++;
+	switch_mutex_unlock(mod_sofia_globals.mutex);
+
 	profile->s_root = su_root_create(NULL);
 	profile->home = su_home_new(sizeof(*profile->home));
 
@@ -287,7 +291,7 @@
 
 	if (!sofia_glue_init_sql(profile)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
-		return NULL;
+		goto end;
 	}
 
 
@@ -350,8 +354,11 @@
 	su_root_destroy(profile->s_root);
 	pool = profile->pool;
 	switch_core_destroy_memory_pool(&pool);
+
+ end:
+	
 	switch_mutex_lock(mod_sofia_globals.mutex);
-	mod_sofia_globals.running = 0;
+	mod_sofia_globals.threads--;
 	switch_mutex_unlock(mod_sofia_globals.mutex);
 
 	return NULL;
@@ -402,9 +409,7 @@
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	sofia_profile_t *profile = NULL;
 	char url[512] = "";
-	switch_mutex_lock(mod_sofia_globals.mutex);
-	mod_sofia_globals.running = 1;
-	switch_mutex_unlock(mod_sofia_globals.mutex);
+
 
 	if (!reload) {
 		su_init();



More information about the Freeswitch-svn mailing list