From cbef00ce1fcaa65147238c4f01aa08f774e019fd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 24 Aug 2008 01:52:27 +0000 Subject: [PATCH] tweak git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9361 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.c | 4 ++-- src/mod/endpoints/mod_sofia/mod_sofia.h | 2 +- src/mod/endpoints/mod_sofia/sofia.c | 3 +-- .../formats/mod_local_stream/mod_local_stream.c | 14 ++++++++++++-- src/switch_loadable_module.c | 2 ++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index e8618ba82a..c882e58005 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -2226,8 +2226,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) mod_sofia_globals.running = 1; switch_mutex_unlock(mod_sofia_globals.mutex); - switch_queue_create(&mod_sofia_globals.presence_queue, 500000, mod_sofia_globals.pool); - switch_queue_create(&mod_sofia_globals.mwi_queue, 500000, mod_sofia_globals.pool); + switch_queue_create(&mod_sofia_globals.presence_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool); + switch_queue_create(&mod_sofia_globals.mwi_queue, SOFIA_QUEUE_SIZE, mod_sofia_globals.pool); if (config_sofia(0, NULL) != SWITCH_STATUS_SUCCESS) { mod_sofia_globals.running = 0; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 6b342d5aba..b3b0e756a2 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -38,7 +38,7 @@ /*************************************************************************************************************************************************************/ #define IREG_SECONDS 30 #define GATEWAY_SECONDS 1 - +#define SOFIA_QUEUE_SIZE 50000 #define HAVE_APR #include #include diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index cc9364741b..8fdb2374fb 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -358,7 +358,6 @@ void sofia_event_callback(nua_event_t event, nua_handle_bind(nh, NULL); } sofia_private->destroy_me = 12; - free(sofia_private); sofia_private = NULL; } @@ -443,7 +442,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread sofia_set_pflag_locked(profile, PFLAG_WORKER_RUNNING); - switch_queue_create(&profile->sql_queue, 500000, profile->pool); + switch_queue_create(&profile->sql_queue, SOFIA_QUEUE_SIZE, profile->pool); qsize = switch_queue_size(profile->sql_queue); diff --git a/src/mod/formats/mod_local_stream/mod_local_stream.c b/src/mod/formats/mod_local_stream/mod_local_stream.c index ffb1da6a45..e31774146b 100644 --- a/src/mod/formats/mod_local_stream/mod_local_stream.c +++ b/src/mod/formats/mod_local_stream/mod_local_stream.c @@ -87,7 +87,8 @@ static int do_rand(void) { double r; int index; - srand(getpid() + ++S); + unsigned int seed = ++S + getpid(); + srand(seed); r = ((double) rand() / ((double) (RAND_MAX) + (double) (1))); index = (int) (r * 9) + 1; return index; @@ -230,7 +231,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void } switch_core_timer_destroy(&timer); - if (source->shuffle) { + if (RUNNING && source->shuffle) { skip = do_rand(); } } @@ -472,6 +473,11 @@ static void launch_threads(void) switch_xml_free(xml); } +static void event_handler(switch_event_t *event) +{ + RUNNING = 0; +} + SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load) { switch_file_interface_t *file_interface; @@ -485,6 +491,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load) file_interface->file_close = local_stream_file_close; file_interface->file_read = local_stream_file_read; + if (switch_event_bind(modname, SWITCH_EVENT_SHUTDOWN, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event handler!\n"); + } + memset(&globals, 0, sizeof(globals)); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, pool); switch_core_hash_init(&globals.source_hash, pool); diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index cd0bd04933..b93bfb8226 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -1149,6 +1149,8 @@ SWITCH_DECLARE(void) switch_loadable_module_shutdown(void) } } + switch_yield(1000000); + for (hi = switch_hash_first(NULL, loadable_modules.module_hash); hi; hi = switch_hash_next(hi)) { switch_hash_this(hi, NULL, NULL, &val); module = (switch_loadable_module_t *) val;