]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_erlang_event Add proper locking for the list of XML bindings
authorAndrew Thompson <andrew@hijacked.us>
Sat, 22 Jan 2011 02:53:03 +0000 (21:53 -0500)
committerAndrew Thompson <andrew@hijacked.us>
Sat, 22 Jan 2011 02:53:03 +0000 (21:53 -0500)
src/mod/event_handlers/mod_erlang_event/handle_msg.c
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h

index 9ae15277fdf0b18c38f0053c5647e85f08394752..87f91fc51b15a356c8888de7ab9c06ad0aaf03be 100644 (file)
@@ -778,7 +778,7 @@ static switch_status_t handle_msg_bind(listener_t *listener, erlang_msg * msg, e
                        binding->process.pid = msg->from;
                        binding->listener = listener;
 
-                       switch_thread_rwlock_wrlock(globals.listener_rwlock);
+                       switch_thread_rwlock_wrlock(globals.bindings_rwlock);
 
                        for (ptr = bindings.head; ptr && ptr->next; ptr = ptr->next);
 
@@ -789,7 +789,7 @@ static switch_status_t handle_msg_bind(listener_t *listener, erlang_msg * msg, e
                        }
 
                        switch_xml_set_binding_sections(bindings.search_binding, switch_xml_get_binding_sections(bindings.search_binding) | section);
-                       switch_thread_rwlock_unlock(globals.listener_rwlock);
+                       switch_thread_rwlock_unlock(globals.bindings_rwlock);
 
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sections %d\n", switch_xml_get_binding_sections(bindings.search_binding));
 
index 1a8bd00790decbcfd0ed645c2cb21e6cc86ade87..900b9655ff651de80e636a234a08bf380f5699cb 100644 (file)
@@ -90,7 +90,7 @@ static void remove_binding(listener_t *listener, erlang_pid * pid)
 {
        struct erlang_binding *ptr, *lst = NULL;
 
-       switch_thread_rwlock_wrlock(globals.listener_rwlock);
+       switch_thread_rwlock_wrlock(globals.bindings_rwlock);
 
        switch_xml_set_binding_sections(bindings.search_binding, SWITCH_XML_SECTION_MAX);
 
@@ -100,7 +100,7 @@ static void remove_binding(listener_t *listener, erlang_pid * pid)
                                if (ptr->next) {
                                        bindings.head = ptr->next;
                                } else {
-                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removed all (only?) listeners\n");
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removed all (only?) binding\n");
                                        bindings.head = NULL;
                                        break;
                                }
@@ -111,13 +111,13 @@ static void remove_binding(listener_t *listener, erlang_pid * pid)
                                        lst->next = NULL;
                                }
                        }
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removed listener\n");
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Removed binding\n");
                } else {
                        switch_xml_set_binding_sections(bindings.search_binding, switch_xml_get_binding_sections(bindings.search_binding) | ptr->section);
                }
        }
 
-       switch_thread_rwlock_unlock(globals.listener_rwlock);
+       switch_thread_rwlock_unlock(globals.bindings_rwlock);
 }
 
 
@@ -381,6 +381,8 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c
 
        section = switch_xml_parse_section_string((char *) sectionstr);
 
+       switch_thread_rwlock_rdlock(globals.bindings_rwlock);
+
        for (ptr = bindings.head; ptr; ptr = ptr->next) {
                if (ptr->section != section)
                        continue;
@@ -417,6 +419,8 @@ static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, c
                switch_mutex_unlock(ptr->listener->sock_mutex);
        }
 
+       switch_thread_rwlock_unlock(globals.bindings_rwlock);
+
        ei_x_free(&buf);
 
        if (!p) {
@@ -1638,6 +1642,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_erlang_event_load)
        memset(&prefs, 0, sizeof(prefs));
 
        switch_thread_rwlock_create(&globals.listener_rwlock, pool);
+       switch_thread_rwlock_create(&globals.bindings_rwlock, pool);
        switch_mutex_init(&globals.fetch_reply_mutex, SWITCH_MUTEX_DEFAULT, pool);
        switch_mutex_init(&globals.listener_count_mutex, SWITCH_MUTEX_UNNESTED, pool);
        switch_core_hash_init(&globals.fetch_reply_hash, pool);
index dacfbd661b455b8022f7711f9c885158f01b2f85..121e7b4f95335e73f2afb69e6c057600b664e2c7 100644 (file)
@@ -161,6 +161,7 @@ struct api_command_struct {
 
 struct globals_struct {
        switch_thread_rwlock_t *listener_rwlock;
+       switch_thread_rwlock_t *bindings_rwlock;
        switch_event_node_t *node;
        switch_mutex_t *ref_mutex;
        switch_mutex_t *fetch_reply_mutex;