change xml hooks to rwlock

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9498 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-09-09 22:47:37 +00:00
parent 4abd35c5a0
commit 8ec9b8f7cb
1 changed files with 15 additions and 13 deletions

View File

@ -139,8 +139,8 @@ struct switch_xml_binding {
static switch_xml_binding_t *BINDINGS = NULL; static switch_xml_binding_t *BINDINGS = NULL;
static switch_xml_t MAIN_XML_ROOT = NULL; static switch_xml_t MAIN_XML_ROOT = NULL;
static switch_memory_pool_t *XML_MEMORY_POOL; static switch_memory_pool_t *XML_MEMORY_POOL;
static switch_mutex_t *XML_LOCK;
static switch_thread_rwlock_t *RWLOCK; static switch_thread_rwlock_t *RWLOCK;
static switch_thread_rwlock_t *B_RWLOCK;
static uint32_t lock_count = 0; static uint32_t lock_count = 0;
struct xml_section_t { struct xml_section_t {
@ -186,7 +186,8 @@ SWITCH_DECLARE(switch_status_t) switch_xml_unbind_search_function(switch_xml_bin
switch_xml_binding_t *ptr, *last = NULL; switch_xml_binding_t *ptr, *last = NULL;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_lock(XML_LOCK);
switch_thread_rwlock_wrlock(B_RWLOCK);
for (ptr = BINDINGS; ptr; ptr = ptr->next) { for (ptr = BINDINGS; ptr; ptr = ptr->next) {
if (ptr == *binding) { if (ptr == *binding) {
if (last) { if (last) {
@ -199,7 +200,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_unbind_search_function(switch_xml_bin
} }
last = ptr; last = ptr;
} }
switch_mutex_unlock(XML_LOCK); switch_thread_rwlock_unlock(B_RWLOCK);
return status; return status;
} }
@ -209,7 +210,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_unbind_search_function_ptr(switch_xml
switch_xml_binding_t *ptr, *last = NULL; switch_xml_binding_t *ptr, *last = NULL;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_lock(XML_LOCK); switch_thread_rwlock_wrlock(B_RWLOCK);
for (ptr = BINDINGS; ptr; ptr = ptr->next) { for (ptr = BINDINGS; ptr; ptr = ptr->next) {
if (ptr->function == function) { if (ptr->function == function) {
if (last) { if (last) {
@ -221,7 +222,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_unbind_search_function_ptr(switch_xml
} }
last = ptr; last = ptr;
} }
switch_mutex_unlock(XML_LOCK); switch_thread_rwlock_unlock(B_RWLOCK);
return status; return status;
} }
@ -239,7 +240,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_searc
binding->sections = sections; binding->sections = sections;
binding->user_data = user_data; binding->user_data = user_data;
switch_mutex_lock(XML_LOCK); switch_thread_rwlock_wrlock(B_RWLOCK);
for (ptr = BINDINGS; ptr && ptr->next; ptr = ptr->next); for (ptr = BINDINGS; ptr && ptr->next; ptr = ptr->next);
if (ptr) { if (ptr) {
@ -247,7 +248,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_searc
} else { } else {
BINDINGS = binding; BINDINGS = binding;
} }
switch_mutex_unlock(XML_LOCK); switch_thread_rwlock_unlock(B_RWLOCK);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -1363,7 +1364,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
switch_xml_binding_t *binding; switch_xml_binding_t *binding;
uint8_t loops = 0; uint8_t loops = 0;
switch_mutex_lock(XML_LOCK); switch_thread_rwlock_rdlock(B_RWLOCK);
for (binding = BINDINGS; binding; binding = binding->next) { for (binding = BINDINGS; binding; binding = binding->next) {
switch_xml_section_t sections = switch_xml_parse_section_string(section); switch_xml_section_t sections = switch_xml_parse_section_string(section);
@ -1398,7 +1399,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
} }
} }
} }
switch_mutex_unlock(XML_LOCK); switch_thread_rwlock_unlock(B_RWLOCK);
for (;;) { for (;;) {
if (!xml) { if (!xml) {
@ -1571,13 +1572,13 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **e
uint8_t hasmain = 0, errcnt = 0; uint8_t hasmain = 0, errcnt = 0;
switch_xml_t new_main; switch_xml_t new_main;
switch_mutex_lock(XML_LOCK); //switch_mutex_lock(XML_LOCK);
if (MAIN_XML_ROOT) { if (MAIN_XML_ROOT) {
hasmain++; hasmain++;
if (!reload) { if (!reload) {
switch_mutex_unlock(XML_LOCK); //switch_mutex_unlock(XML_LOCK);
return switch_xml_root(); return switch_xml_root();
} }
switch_thread_rwlock_wrlock(RWLOCK); switch_thread_rwlock_wrlock(RWLOCK);
@ -1609,7 +1610,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **e
if (hasmain) { if (hasmain) {
switch_thread_rwlock_unlock(RWLOCK); switch_thread_rwlock_unlock(RWLOCK);
} }
switch_mutex_unlock(XML_LOCK); //switch_mutex_unlock(XML_LOCK);
if (errcnt == 0) { if (errcnt == 0) {
switch_event_t *event; switch_event_t *event;
@ -1630,8 +1631,9 @@ SWITCH_DECLARE(switch_status_t) switch_xml_init(switch_memory_pool_t *pool, cons
XML_MEMORY_POOL = pool; XML_MEMORY_POOL = pool;
*err = "Success"; *err = "Success";
switch_mutex_init(&XML_LOCK, SWITCH_MUTEX_NESTED, XML_MEMORY_POOL); //switch_mutex_init(&XML_LOCK, SWITCH_MUTEX_NESTED, XML_MEMORY_POOL);
switch_thread_rwlock_create(&RWLOCK, XML_MEMORY_POOL); switch_thread_rwlock_create(&RWLOCK, XML_MEMORY_POOL);
switch_thread_rwlock_create(&B_RWLOCK, XML_MEMORY_POOL);
assert(pool != NULL); assert(pool != NULL);