]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add initial-event-threads to switch.conf.xml
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 29 Jun 2012 16:39:49 +0000 (11:39 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 29 Jun 2012 16:39:49 +0000 (11:39 -0500)
src/include/switch_event.h
src/switch_core.c
src/switch_event.c

index 5909c0e0c07b7ff84b197ae1e7443af6227324b1..d0474a6929eba4688a6fef6c54957ad9df617500 100644 (file)
@@ -403,6 +403,7 @@ SWITCH_DECLARE(void) switch_event_deliver(switch_event_t **event);
 SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix, switch_hash_t *vars_map);
 SWITCH_DECLARE(int) switch_event_check_permission_list(switch_event_t *list, const char *name);
 SWITCH_DECLARE(void) switch_event_add_presence_data_cols(switch_channel_t *channel, switch_event_t *event, const char *prefix);
+SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max);
 
 ///\}
 
index d706563f835984b1ec7ea9103a14d58423cfed55..2a4cae408faa59fc57517447d32473ca5af317ae 100644 (file)
@@ -1538,7 +1538,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
        switch_log_init(runtime.memory_pool, runtime.colorize_console);
 
        if (flags & SCF_MINIMAL) return SWITCH_STATUS_SUCCESS;
-                                                                                                          
+                       
        runtime.tipping_point = 0;
        runtime.timer_affinity = -1;
        runtime.microseconds_per_tick = 20000;
@@ -1813,6 +1813,23 @@ static void switch_load_core_config(const char *file)
                                        switch_core_min_idle_cpu(atof(val));
                                } else if (!strcasecmp(var, "tipping-point") && !zstr(val)) {
                                        runtime.tipping_point = atoi(val);
+                               } else if (!strcasecmp(var, "initial-event-threads") && !zstr(val)) {
+                                       int tmp = atoi(val);
+
+
+                                       if (tmp > runtime.cpu_count / 2) {
+                                               tmp = runtime.cpu_count / 2;
+                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "This value cannot be higher than %d so setting it to that value\n", 
+                                                                                 runtime.cpu_count / 2);
+                                       }
+
+                                       if (tmp < 1) {
+                                               tmp = 1;
+                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "This value cannot be lower than 1 so setting it to that level\n");
+                                       }
+
+                                       switch_event_launch_dispatch_threads(tmp);
+
                                } else if (!strcasecmp(var, "1ms-timer") && switch_true(val)) {
                                        runtime.microseconds_per_tick = 1000;
                                } else if (!strcasecmp(var, "timer-affinity") && !zstr(val)) {
index defae3586c370d04ca0654d38de4da8379631ae2..0f08b496c077baa9365ff91969da96b463ebf6b3 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <switch.h>
 #include <switch_event.h>
+
 //#define SWITCH_EVENT_RECYCLE
 #define DISPATCH_QUEUE_LEN 100
 //#define DEBUG_DISPATCH_QUEUES
@@ -87,7 +88,6 @@ static uint64_t EVENT_SEQUENCE_NR = 0;
 static switch_queue_t *EVENT_RECYCLE_QUEUE = NULL;
 static switch_queue_t *EVENT_HEADER_RECYCLE_QUEUE = NULL;
 #endif
-static void launch_dispatch_threads(uint32_t max, switch_memory_pool_t *pool);
 
 static char *my_dup(const char *s)
 {
@@ -305,7 +305,7 @@ static switch_status_t switch_event_queue_dispatch_event(switch_event_t **eventp
                
                if (launch) {
                        if (SOFT_MAX_DISPATCH + 1 < MAX_DISPATCH) {
-                               launch_dispatch_threads(SOFT_MAX_DISPATCH + 1, RUNTIME_POOL);
+                               switch_event_launch_dispatch_threads(SOFT_MAX_DISPATCH + 1);
                        }
                }
 
@@ -515,13 +515,15 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void)
        return SWITCH_STATUS_SUCCESS;
 }
 
-static void launch_dispatch_threads(uint32_t max, switch_memory_pool_t *pool)
+SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max)
 {
        switch_threadattr_t *thd_attr;
        uint32_t index = 0;
        int launched = 0;
        uint32_t sanity = 200;
 
+       switch_memory_pool_t *pool = RUNTIME_POOL;
+
        if (max > MAX_DISPATCH) {
                return;
        }
@@ -532,6 +534,7 @@ static void launch_dispatch_threads(uint32_t max, switch_memory_pool_t *pool)
 
        for (index = SOFT_MAX_DISPATCH; index < max && index < MAX_DISPATCH; index++) {
                if (EVENT_DISPATCH_QUEUE_THREADS[index]) {
+                       printf("Index exists continue\n");
                        continue;
                }
 
@@ -540,13 +543,13 @@ static void launch_dispatch_threads(uint32_t max, switch_memory_pool_t *pool)
                switch_threadattr_priority_increase(thd_attr);
                switch_thread_create(&EVENT_DISPATCH_QUEUE_THREADS[index], thd_attr, switch_event_dispatch_thread, EVENT_DISPATCH_QUEUE, pool);
                while(--sanity && !EVENT_DISPATCH_QUEUE_RUNNING[index]) switch_yield(10000);
+
                if (index == 1) {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Create event dispatch thread %d\n", index);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Create event dispatch thread %d\n", index);
                } else {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Create additional event dispatch thread %d\n", index);
                }
                launched++;
-               break;
        }
 
        SOFT_MAX_DISPATCH = index;
@@ -598,7 +601,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
        //switch_threadattr_priority_increase(thd_attr);
 
        switch_queue_create(&EVENT_DISPATCH_QUEUE, DISPATCH_QUEUE_LEN * MAX_DISPATCH, pool);
-       launch_dispatch_threads(1, RUNTIME_POOL);
+       switch_event_launch_dispatch_threads(1);
 
        //switch_thread_create(&EVENT_QUEUE_THREADS[0], thd_attr, switch_event_thread, EVENT_QUEUE[0], RUNTIME_POOL);
        //switch_thread_create(&EVENT_QUEUE_THREADS[1], thd_attr, switch_event_thread, EVENT_QUEUE[1], RUNTIME_POOL);