diff --git a/src/switch_core.c b/src/switch_core.c index 6f382f3725..3f490cf002 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1646,6 +1646,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc runtime.console = stdout; } + SSL_library_init(); switch_ssl_init_ssl_locks(); switch_curl_init(); @@ -1779,11 +1780,6 @@ static void switch_load_core_config(const char *file) switch_core_hash_insert(runtime.ptimes, "isac", &d_30); switch_core_hash_insert(runtime.ptimes, "G723", &d_30); - if (runtime.cpu_count == 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, - "Implicitly setting events-use-dispatch based on a single CPU\n"); - runtime.events_use_dispatch = 1; - } if ((xml = switch_xml_open_cfg(file, &cfg, NULL))) { switch_xml_t settings, param; @@ -1957,7 +1953,7 @@ static void switch_load_core_config(const char *file) } else if (!strcasecmp(var, "tipping-point") && !zstr(val)) { runtime.tipping_point = atoi(val); } else if (!strcasecmp(var, "events-use-dispatch") && !zstr(val)) { - runtime.events_use_dispatch = 1; + runtime.events_use_dispatch = switch_true(val); } else if (!strcasecmp(var, "initial-event-threads") && !zstr(val)) { int tmp; @@ -2079,6 +2075,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t } runtime.runlevel++; + runtime.events_use_dispatch = 1; switch_core_set_signal_handlers(); switch_load_network_lists(SWITCH_FALSE); diff --git a/src/switch_event.c b/src/switch_event.c index 777ebcd15e..eb6e2d4c2b 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -568,6 +568,25 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) return SWITCH_STATUS_SUCCESS; } +static void check_dispatch(void) +{ + if (!EVENT_DISPATCH_QUEUE) { + switch_mutex_lock(BLOCK); + + if (!EVENT_DISPATCH_QUEUE) { + switch_queue_create(&EVENT_DISPATCH_QUEUE, DISPATCH_QUEUE_LEN * MAX_DISPATCH, THRUNTIME_POOL); + switch_event_launch_dispatch_threads(1); + + while (!THREAD_COUNT) { + switch_cond_next(); + } + } + switch_mutex_unlock(BLOCK); + } +} + + + SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max) { switch_threadattr_t *thd_attr; @@ -577,6 +596,8 @@ SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max) switch_memory_pool_t *pool = RUNTIME_POOL; + check_dispatch(); + if (max > MAX_DISPATCH) { return; } @@ -646,6 +667,8 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool) switch_queue_create(&EVENT_HEADER_RECYCLE_QUEUE, 250000, THRUNTIME_POOL); #endif + check_dispatch(); + switch_mutex_lock(EVENT_QUEUE_MUTEX); SYSTEM_RUNNING = 1; switch_mutex_unlock(EVENT_QUEUE_MUTEX); @@ -1900,19 +1923,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_fire_detailed(const char *file, con if (runtime.events_use_dispatch) { - if (!EVENT_DISPATCH_QUEUE) { - switch_mutex_lock(BLOCK); - - if (!EVENT_DISPATCH_QUEUE) { - switch_queue_create(&EVENT_DISPATCH_QUEUE, DISPATCH_QUEUE_LEN * MAX_DISPATCH, THRUNTIME_POOL); - switch_event_launch_dispatch_threads(1); - - while (!THREAD_COUNT) { - switch_cond_next(); - } - } - switch_mutex_unlock(BLOCK); - } + check_dispatch(); if (switch_event_queue_dispatch_event(event) != SWITCH_STATUS_SUCCESS) { switch_event_destroy(event);