From 7e9f64ee71ecf7d028fc0b7666666834bac584be Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 30 Jul 2008 18:54:37 +0000 Subject: [PATCH] update git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9210 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_xml.h | 1 + src/switch_xml.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h index b7493ea1bc..be8a2e62f1 100644 --- a/src/include/switch_xml.h +++ b/src/include/switch_xml.h @@ -215,6 +215,7 @@ SWITCH_DECLARE(const char **) switch_xml_pi(switch_xml_t xml, const char *target ///\param xml the xml node ///\note in the case of the root node the readlock will be lifted SWITCH_DECLARE(void) switch_xml_free(switch_xml_t xml); +SWITCH_DECLARE(void) switch_xml_free_in_thread(switch_xml_t xml, int stacksize); ///\brief returns parser error message or empty string if none ///\param xml the xml node diff --git a/src/switch_xml.c b/src/switch_xml.c index 4793e8847c..6f4aeedb46 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -1523,6 +1523,43 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_root(void) return MAIN_XML_ROOT; } + +struct destroy_xml { + switch_xml_t xml; + switch_memory_pool_t *pool; +}; + +static void *SWITCH_THREAD_FUNC destroy_thread(switch_thread_t *thread, void *obj) +{ + struct destroy_xml *dx = (struct destroy_xml *) obj; + switch_memory_pool_t *pool = dx->pool; + switch_xml_free(dx->xml); + switch_core_destroy_memory_pool(&pool); + return NULL; +} + +SWITCH_DECLARE(void) switch_xml_free_in_thread(switch_xml_t xml, int stacksize) +{ + switch_thread_t *thread; + switch_threadattr_t *thd_attr; + switch_memory_pool_t *pool = NULL; + struct destroy_xml *dx; + + switch_core_new_memory_pool(&pool); + + switch_threadattr_create(&thd_attr, pool); + switch_threadattr_detach_set(thd_attr, 1); + // TBD figure out how much space we need by looking at the xml_t when stacksize == 0 + switch_threadattr_stacksize_set(thd_attr, stacksize); + + dx = switch_core_alloc(pool, sizeof(*dx)); + dx->pool = pool; + dx->xml = xml; + + switch_thread_create(&thread, thd_attr, destroy_thread, dx, pool); + +} + static char not_so_threadsafe_error_buffer[256] = ""; SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **err) @@ -1559,6 +1596,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_root(uint8_t reload, const char **e MAIN_XML_ROOT = new_main; switch_set_flag(MAIN_XML_ROOT, SWITCH_XML_ROOT); switch_xml_free(old_root); + //switch_xml_free_in_thread(old_root); } } else { *err = "Cannot Open log directory or XML Root!";