[Freeswitch-trunk] [commit] r13900 - freeswitch/trunk/src/mod/event_handlers/mod_erlang_event

FreeSWITCH SVN andrew at freeswitch.org
Mon Jun 22 16:38:23 PDT 2009


Author: andrew
Date: Mon Jun 22 18:38:23 2009
New Revision: 13900

Log:
Unify outbound session cleanup code, possibly fixes MODEVENT-47


Modified:
   freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c

Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	Mon Jun 22 18:38:23 2009
@@ -304,6 +304,7 @@
 	return l;
 }
 
+
 static void add_session_elem_to_listener(listener_t *listener, session_elem_t *session_element)
 {
 	switch_mutex_lock(listener->session_mutex);
@@ -312,6 +313,7 @@
 	switch_mutex_unlock(listener->session_mutex);
 }
 
+
 static void remove_session_elem_from_listener(listener_t *listener, session_elem_t *session_element)
 {
 	session_elem_t *s, *last = NULL;
@@ -320,10 +322,9 @@
 	if (!session_element)
 		return;
 
-	switch_mutex_lock(listener->session_mutex);
 	for(s = listener->session_list; s; s = s->next) {
 		if (s == session_element) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing session element\n");
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removing session element for %s\n", session_element->uuid_str);
 			if (last) {
 				last->next = s->next;
 			} else {
@@ -335,10 +336,17 @@
 			}
 			/* this allows the application threads to exit */
 			switch_clear_flag_locked(s, LFLAG_SESSION_ALIVE);
+			switch_safe_free(s);
 			break;
 		}
 		last = s;
 	}
+}
+
+
+static void remove_session_elem_from_listener_locked(listener_t *listener, session_elem_t *session_element) {
+	switch_mutex_lock(listener->session_mutex);
+	remove_session_elem_from_listener(listener, session_element);
 	switch_mutex_unlock(listener->session_mutex);
 }
 
@@ -557,14 +565,7 @@
 			if (pevent->event_id == SWITCH_EVENT_CHANNEL_DESTROY) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy event for attached session for %s\n", sp->uuid_str);
 
-				/* remove session from list */
-				if (last)
-					last->next = sp->next;
-				else
-					listener->session_list = sp->next;
-
 				/* this allows the application threads to exit */
-				switch_clear_flag_locked(sp, LFLAG_SESSION_ALIVE);
 				removed = sp;
 
 				ei_x_new_with_version(&ebuf);
@@ -583,7 +584,7 @@
 		}
 		sp = sp->next;
 		if (removed) {
-			switch_safe_free(removed)
+			remove_session_elem_from_listener(listener, removed);
 		} else {
 			last = sp;
 		}
@@ -682,7 +683,7 @@
 					s->uuid_str);
 			/* TODO - if a spawned process that was handling an outbound call fails.. what do we do with the call? */
 		}
-		remove_session_elem_from_listener(listener, s);
+		remove_session_elem_from_listener_locked(listener, s);
 	}
 
 	if (listener->log_process.type == ERLANG_PID && !ei_compare_pids(&listener->log_process.pid, pid)) {
@@ -1107,7 +1108,7 @@
 {
 	/* create a session list element */
 	session_elem_t* session_element = session_elem_create(listener, session);
-	
+
 	session_element->process.type = ERLANG_PID;
 	memcpy(&session_element->process.pid, pid, sizeof(erlang_pid));
 	switch_set_flag(session_element, LFLAG_SESSION_ALIVE);
@@ -1167,7 +1168,7 @@
 	while (!(p = switch_core_hash_find(listener->spawn_pid_hash, hash)) || p == &globals.WAITING) {
 		if (i > 50) { /* half a second timeout */
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out when waiting for outbound pid\n");
-			remove_session_elem_from_listener(listener,session_element);
+			remove_session_elem_from_listener_locked(listener,session_element);
 			switch_core_hash_insert(listener->spawn_pid_hash, hash, &globals.TIMEOUT); /* TODO lock this? */
 			return NULL;
 		}



More information about the Freeswitch-trunk mailing list