[Freeswitch-svn] [commit] r10289 - freeswitch/trunk/src/mod/event_handlers/mod_event_socket

Freeswitch SVN anthm at freeswitch.org
Fri Nov 7 11:42:46 PST 2008


Author: anthm
Date: Fri Nov  7 09:48:49 2008
New Revision: 10289

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

Log:
fix MODEVENT-32

Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Fri Nov  7 09:48:49 2008
@@ -87,8 +87,12 @@
 typedef struct listener listener_t;
 
 static struct {
+	switch_mutex_t *listener_mutex;	
+	switch_event_node_t *node;
+} globals;
+
+static struct {
 	switch_socket_t *sock;
-	switch_mutex_t *mutex;
 	switch_mutex_t *sock_mutex;
 	listener_t *listeners;
 	uint8_t ready;
@@ -114,9 +118,9 @@
 static uint32_t next_id(void)
 {
 	uint32_t id;
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
     id = ++prefs.id;
-    switch_mutex_unlock(listen_list.mutex);
+    switch_mutex_unlock(globals.listener_mutex);
 	return id;
 }
 
@@ -126,16 +130,11 @@
 static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t *thread, void *obj);
 static void launch_listener_thread(listener_t *listener);
 
-static struct {
-	switch_event_node_t *node;
-} globals;
-
-
 static switch_status_t socket_logger(const switch_log_node_t *node, switch_log_level_t level)
 {
 	listener_t *l;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		if (switch_test_flag(l, LFLAG_LOG) && l->level >= node->level) {
 			char *data = strdup(node->data);
@@ -160,7 +159,7 @@
 			}
 		}
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -212,7 +211,7 @@
 
 	lp = listen_list.listeners;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	while(lp) {
 		int send = 0;
 		
@@ -321,7 +320,7 @@
 		}
 
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 }
 
 SWITCH_STANDARD_APP(socket_function)
@@ -456,11 +455,11 @@
 	}
 	switch_event_unbind(&globals.node);
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		close_socket(&l->sock);
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 
 
 
@@ -470,17 +469,17 @@
 static void add_listener(listener_t *listener)
 {
 	/* add me to the listeners so I get events */
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	listener->next = listen_list.listeners;
 	listen_list.listeners = listener;
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 }
 
 static void remove_listener(listener_t *listener)
 {
 	listener_t *l, *last = NULL;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		if (l == listener) {
 			if (last) {
@@ -491,7 +490,7 @@
 		}
 		last = l;
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 }
 
 
@@ -499,7 +498,7 @@
 {
 	listener_t *l, *r = NULL;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	for (l = listen_list.listeners; l; l = l->next) {
 		if (l->id && l->id == id) {
 			if (switch_thread_rwlock_tryrdlock(l->rwlock) == SWITCH_STATUS_SUCCESS) {
@@ -508,7 +507,7 @@
 			break;
 		}
 	}
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 	return r;
 }
 
@@ -755,6 +754,8 @@
 	switch_application_interface_t *app_interface;
 	switch_api_interface_t *api_interface;
 
+	switch_mutex_init(&globals.listener_mutex, SWITCH_MUTEX_NESTED, pool);
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	SWITCH_ADD_APP(app_interface, "socket", "Connect to a socket", "Connect to a socket", socket_function, "<ip>[:<port>]", SAF_SUPPORT_NOMEDIA);
@@ -1591,9 +1592,9 @@
 	switch_channel_t *channel = NULL;
 	switch_event_t *revent = NULL;
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	prefs.threads++;
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 
 	switch_assert(listener != NULL);
 
@@ -1785,9 +1786,9 @@
 		switch_core_destroy_memory_pool(&pool);
 	}
 
-	switch_mutex_lock(listen_list.mutex);
+	switch_mutex_lock(globals.listener_mutex);
 	prefs.threads--;
-	switch_mutex_unlock(listen_list.mutex);
+	switch_mutex_unlock(globals.listener_mutex);
 
 	return NULL;
 }
@@ -1871,7 +1872,7 @@
 		return SWITCH_STATUS_TERM;
 	}
 
-	switch_mutex_init(&listen_list.mutex, SWITCH_MUTEX_NESTED, pool);
+
 	switch_mutex_init(&listen_list.sock_mutex, SWITCH_MUTEX_NESTED, pool);
 
 



More information about the Freeswitch-svn mailing list