]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
more priority tweaks
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 1 Oct 2012 15:20:48 +0000 (10:20 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 1 Oct 2012 15:20:48 +0000 (10:20 -0500)
16 files changed:
src/include/switch_apr.h
src/include/switch_types.h
src/mod/applications/mod_callcenter/mod_callcenter.c
src/mod/applications/mod_conference/mod_conference.c
src/mod/applications/mod_voicemail/mod_voicemail.c
src/mod/endpoints/mod_khomp/commons/base/system/freeswitch/thread.hpp
src/mod/endpoints/mod_skypopen/mod_skypopen.c
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c
src/switch_apr.c
src/switch_core.c
src/switch_core_session.c
src/switch_core_sqldb.c
src/switch_event.c
src/switch_loadable_module.c

index bd19353991ff65107f36eb7ebea04f9518f26247..671052ab30275b2d4c66830cf3a6d08ec6bab8b9 100644 (file)
@@ -989,7 +989,7 @@ SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *bu
 //APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr, switch_size_t stacksize)
 SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadattr_t *attr, switch_size_t stacksize);
 
-SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_increase(switch_threadattr_t *attr);
+SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority);
 
 
 /**
index 5f3a4fa25843198806ef8883fa78e945d0425148..f9d84764549a459a2560222541e040f0d0695673 100644 (file)
@@ -2016,6 +2016,13 @@ typedef switch_status_t (*switch_module_shutdown_t) SWITCH_MODULE_SHUTDOWN_ARGS;
 #define SWITCH_MODULE_RUNTIME_FUNCTION(name) switch_status_t name SWITCH_MODULE_RUNTIME_ARGS
 #define SWITCH_MODULE_SHUTDOWN_FUNCTION(name) switch_status_t name SWITCH_MODULE_SHUTDOWN_ARGS
 
+typedef enum {
+       SWITCH_PRI_LOW = 1,
+       SWITCH_PRI_NORMAL = 10,
+       SWITCH_PRI_IMPORTANT = 50,
+       SWITCH_PRI_REALTIME = 99,
+} switch_thread_priority_t;
+
 typedef enum {
        SMODF_NONE = 0,
        SMODF_GLOBAL_SYMBOLS = (1 << 0)
index df8670f2ee68d617239653508b280c94b7b51e4a..e6f7ea794519e7fc1044eb41f29ef902abd7b21f 100644 (file)
@@ -2272,7 +2272,7 @@ void cc_agent_dispatch_thread_start(void)
        switch_threadattr_create(&thd_attr, globals.pool);
        switch_threadattr_detach_set(thd_attr, 1);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(thd_attr);
+       switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
        switch_thread_create(&thread, thd_attr, cc_agent_dispatch_thread_run, NULL, globals.pool);
 }
 
index d84f3b6f7d077e079d8f3ddee32c8a2ab90db9ee..3acb7d6c55585560447b2c1d0acd7ccdd67a4d1a 100644 (file)
@@ -7748,7 +7748,7 @@ static void launch_conference_thread(conference_obj_t *conference)
        switch_set_flag_locked(conference, CFLAG_RUNNING);
        switch_threadattr_create(&thd_attr, conference->pool);
        switch_threadattr_detach_set(thd_attr, 1);
-       switch_threadattr_priority_increase(thd_attr);
+       switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
        switch_mutex_lock(globals.hash_mutex);
        switch_mutex_unlock(globals.hash_mutex);
index 51677c5b3f75f9cc64de0bfac52ca7e40703790c..78eb57a20adea96d5fb24bcd433d0959c86e0293 100644 (file)
@@ -3930,7 +3930,7 @@ void vm_event_thread_start(void)
        switch_threadattr_create(&thd_attr, globals.pool);
        switch_threadattr_detach_set(thd_attr, 1);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(thd_attr);
+       switch_threadattr_priority_set(thd_attr, SWITCH_PRI_IMPORTANT);
        switch_thread_create(&thread, thd_attr, vm_event_thread_run, NULL, globals.pool);
 }
 
index 9e5abc43726a2209e87fe89d992447bdf22d7017..3c61b6a6ecf074580a45f2759483b5b1a3378189 100644 (file)
@@ -288,7 +288,10 @@ private:
         return true;
 
 /*
-        //BUG in Freeswitch
+        //BUG in Freeswitch  
+
+THANKS FOR NOT REPORTING IT SO WE MUST LIVE WITH A PROBLEM YOU KNOW ABOUT .....
+
         if(switch_threadattr_priority_increase(
                 (switch_threadattr_t *)_thread_info->_attribute) != 0)
             return false;
index 43253a71e919e974036c8d9fb90721d5fe589019..c3b5d81681c3b9ea9f37c32f0a766352972c292d 100644 (file)
@@ -1741,7 +1741,7 @@ static switch_status_t load_config(int reload_type)
                                switch_threadattr_create(&skypopen_api_thread_attr, skypopen_module_pool);
                                switch_threadattr_detach_set(skypopen_api_thread_attr, 0);
                                switch_threadattr_stacksize_set(skypopen_api_thread_attr, SWITCH_THREAD_STACKSIZE);
-                               //switch_threadattr_priority_increase(skypopen_api_thread_attr);
+
                                switch_thread_create(&globals.SKYPOPEN_INTERFACES[interface_id].skypopen_api_thread,
                                                                         skypopen_api_thread_attr, skypopen_do_skypeapi_thread, &globals.SKYPOPEN_INTERFACES[interface_id],
                                                                         skypopen_module_pool);
@@ -1751,7 +1751,7 @@ static switch_status_t load_config(int reload_type)
                                switch_threadattr_create(&skypopen_signaling_thread_attr, skypopen_module_pool);
                                switch_threadattr_detach_set(skypopen_signaling_thread_attr, 0);
                                switch_threadattr_stacksize_set(skypopen_signaling_thread_attr, SWITCH_THREAD_STACKSIZE);
-                               //switch_threadattr_priority_increase(skypopen_signaling_thread_attr);
+
                                switch_thread_create(&globals.SKYPOPEN_INTERFACES[interface_id].skypopen_signaling_thread, skypopen_signaling_thread_attr,
                                                                         skypopen_signaling_thread_func, &globals.SKYPOPEN_INTERFACES[interface_id], skypopen_module_pool);
 
@@ -2272,7 +2272,7 @@ int start_audio_threads(private_t *tech_pvt)
        switch_threadattr_create(&tcp_srv_thread_thd_attr, skypopen_module_pool);
        switch_threadattr_detach_set(tcp_srv_thread_thd_attr, 0);
        switch_threadattr_stacksize_set(tcp_srv_thread_thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(tcp_srv_thread_thd_attr);
+       switch_threadattr_priority_set(tcp_srv_thread_thd_attr, SWITCH_PRI_REALTIME);
        switch_mutex_lock(tech_pvt->mutex_thread_audio_srv);
        //DEBUGA_SKYPE("debugging_hangup srv lock\n", SKYPOPEN_P_LOG);
        if (switch_thread_create(&tech_pvt->tcp_srv_thread, tcp_srv_thread_thd_attr, skypopen_do_tcp_srv_thread, tech_pvt, skypopen_module_pool) ==
@@ -2290,7 +2290,7 @@ int start_audio_threads(private_t *tech_pvt)
        switch_threadattr_create(&tcp_cli_thread_thd_attr, skypopen_module_pool);
        switch_threadattr_detach_set(tcp_cli_thread_thd_attr, 0);
        switch_threadattr_stacksize_set(tcp_cli_thread_thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(tcp_cli_thread_thd_attr);
+       switch_threadattr_priority_set(tcp_cli_thread_thd_attr, SWITCH_PRI_REALTIME);
        switch_mutex_lock(tech_pvt->mutex_thread_audio_cli);
        //DEBUGA_SKYPE("debugging_hangup cli lock\n", SKYPOPEN_P_LOG);
        if (switch_thread_create(&tech_pvt->tcp_cli_thread, tcp_cli_thread_thd_attr, skypopen_do_tcp_cli_thread, tech_pvt, skypopen_module_pool) ==
index 2793cd73540db9e788ff95c4212f8cc43d736379..3b5277647fd44c5e5db83feb903d5144488d6a34 100644 (file)
@@ -1647,7 +1647,7 @@ void sofia_msg_thread_start(int idx)
 
                                switch_threadattr_create(&thd_attr, mod_sofia_globals.pool);
                                switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-                               switch_threadattr_priority_increase(thd_attr);
+                               switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
                                switch_thread_create(&mod_sofia_globals.msg_queue_thread[i], 
                                                                         thd_attr, 
                                                                         sofia_msg_thread_run, 
@@ -2373,7 +2373,7 @@ switch_thread_t *launch_sofia_worker_thread(sofia_profile_t *profile)
 
        switch_threadattr_create(&thd_attr, profile->pool);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(thd_attr);
+       switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
        switch_thread_create(&thread, thd_attr, sofia_profile_worker_thread_run, profile, profile->pool);
 
        while (!sofia_test_pflag(profile, PFLAG_WORKER_RUNNING)) {
@@ -2753,7 +2753,7 @@ void launch_sofia_profile_thread(sofia_profile_t *profile)
        switch_threadattr_create(&thd_attr, profile->pool);
        switch_threadattr_detach_set(thd_attr, 1);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(thd_attr);
+       switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
        switch_thread_create(&thread, thd_attr, sofia_profile_thread_run, profile, profile->pool);
 }
 
@@ -6114,7 +6114,6 @@ static void launch_media_on_hold(switch_core_session_t *session)
        switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session));
        switch_threadattr_detach_set(thd_attr, 1);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(thd_attr);
        switch_thread_create(&thread, thd_attr, media_on_hold_thread_run, session, switch_core_session_get_pool(session));
 }
 
@@ -7198,7 +7197,6 @@ static void launch_nightmare_xfer(nightmare_xfer_helper_t *nhelper)
        switch_threadattr_create(&thd_attr, nhelper->pool);
        switch_threadattr_detach_set(thd_attr, 1);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(thd_attr);
        switch_thread_create(&thread, thd_attr, nightmare_xfer_thread_run, nhelper, nhelper->pool);
 }
 
index 045ea7a8279e568abce101ab495561c802967d92..10d741bca4063d3334569f871cd2073e2850acda 100644 (file)
@@ -1577,7 +1577,7 @@ void sofia_presence_event_thread_start(void)
        switch_threadattr_create(&thd_attr, mod_sofia_globals.pool);
        switch_threadattr_detach_set(thd_attr, 1);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(thd_attr);
+       switch_threadattr_priority_set(thd_attr, SWITCH_PRI_IMPORTANT);
        switch_thread_create(&thread, thd_attr, sofia_presence_event_thread_run, NULL, mod_sofia_globals.pool);
 }
 
index 3e39e6540714a1bbef3bf2b8dec11f2d258c46bb..81b0ef240f85c7393bd806dad70a7b1550c1d590 100644 (file)
@@ -126,7 +126,7 @@ static void launch_monitor_thread(xml_binding_t *binding)
 
        switch_threadattr_create(&thd_attr, globals.pool);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_threadattr_priority_increase(thd_attr);
+       switch_threadattr_priority_set(thd_attr, SWITCH_PRI_IMPORTANT);
        switch_thread_create(&binding->thread, thd_attr, monitor_thread_run, binding, globals.pool);
 }
 
index 49b7a9b5c5d456ae7978184ce3b616ad79160206..64e066853ee567603b2732f0ad2882bb945e7ce5 100644 (file)
@@ -614,9 +614,24 @@ SWITCH_DECLARE(const char *) switch_dir_next_file(switch_dir_t *thedir, char *bu
 
 /* thread stubs */
 
+#ifndef WIN32
+struct apr_threadattr_t {
+       apr_pool_t *pool;
+       pthread_attr_t attr;
+       int priority;
+};
+#endif
+
+
 SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t ** new_attr, switch_memory_pool_t *pool)
 {
-       return apr_threadattr_create(new_attr, pool);
+       switch_status_t status;
+
+       if ((status = apr_threadattr_create(new_attr, pool)) == SWITCH_STATUS_SUCCESS) {
+               (*new_attr)->priority = SWITCH_PRI_NORMAL;
+       }
+
+       return status;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_threadattr_detach_set(switch_threadattr_t *attr, int32_t on)
@@ -629,18 +644,10 @@ SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadatt
        return apr_threadattr_stacksize_set(attr, stacksize);
 }
 
-#ifndef WIN32
-struct apr_threadattr_t {
-       apr_pool_t *pool;
-       pthread_attr_t attr;
-       int priority;
-};
-#endif
-
-SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_increase(switch_threadattr_t *attr)
+SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority)
 {
 #ifndef WIN32
-       attr->priority = 99;
+       attr->priority = priority;
 #endif
        return SWITCH_STATUS_SUCCESS;
 }
index 488b7552326541767a8789a9e98823bd76c501f7..1d87d9ce2efd0f2e59f2ccae2d84be8e3ebbe55b 100644 (file)
@@ -533,7 +533,7 @@ SWITCH_DECLARE(switch_thread_t *) switch_core_launch_thread(switch_thread_start_
                ts->objs[0] = obj;
                ts->objs[1] = thread;
                switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-               switch_threadattr_priority_increase(thd_attr);
+               switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
                switch_thread_create(&thread, thd_attr, func, ts, pool);
        }
 
@@ -735,7 +735,7 @@ SWITCH_DECLARE(int32_t) set_realtime_priority(void)
        const char *rt = "/proc/sys/kernel/sched_rt_runtime_us";
        char data[] = "-1\n";
        struct sched_param sched = { 0 };
-       sched.sched_priority = 1;
+       sched.sched_priority = SWITCH_PRI_REALTIME;
        if (sched_setscheduler(0, SCHED_RR, &sched)) {
                sched.sched_priority = 0;
                if (sched_setscheduler(0, SCHED_OTHER, &sched)) {
index eb60968f5d7bda0e880fa58df5e1592e84a903df..6e565dca0639e216e8279b814cc9c5b54eedb449 100644 (file)
@@ -1554,6 +1554,7 @@ static switch_status_t check_queue(void)
                switch_threadattr_create(&thd_attr, node->pool);
                switch_threadattr_detach_set(thd_attr, 1);
                switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+               switch_threadattr_priority_set(thd_attr, SWITCH_PRI_LOW);
 
                if (switch_thread_create(&thread, thd_attr, switch_core_session_thread_pool_worker, node, node->pool) != SWITCH_STATUS_SUCCESS) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Thread Failure!\n");
index 2e3e71f204927bc1fc48ea7e433005ea976a3bed..556e3abab23022c70af9cfb004ce1d6ff5d0cf32 100644 (file)
@@ -2539,7 +2539,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
 
                switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
                switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-               switch_threadattr_priority_increase(thd_attr);
+               switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
                switch_core_sqldb_start_thread();
                switch_thread_create(&sql_manager.db_thread, thd_attr, switch_core_sql_db_thread, NULL, sql_manager.memory_pool);
 
@@ -2641,7 +2641,7 @@ SWITCH_DECLARE(void) switch_core_sqldb_start_thread(void)
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Starting SQL thread.\n");
                        switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
                        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-                       switch_threadattr_priority_increase(thd_attr);
+                       switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
                        switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool);
                } else {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL thread is already running\n");
index 175dadf5cfee2471c4cc0e5f3b0b4152391f6d5e..02d23ee8f7c4ab20e22d149464a139910edcf79d 100644 (file)
@@ -545,7 +545,7 @@ SWITCH_DECLARE(void) switch_event_launch_dispatch_threads(uint32_t max)
 
                switch_threadattr_create(&thd_attr, pool);
                switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-               switch_threadattr_priority_increase(thd_attr);
+               switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
                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);
 
@@ -603,7 +603,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_init(switch_memory_pool_t *pool)
 #endif
 
        //switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       //switch_threadattr_priority_increase(thd_attr);
+
 
        switch_queue_create(&EVENT_DISPATCH_QUEUE, DISPATCH_QUEUE_LEN * MAX_DISPATCH, pool);
        switch_event_launch_dispatch_threads(1);
index d253a75bea27be9c75a368db23e05bb7dc0330eb..718572612e13132f87ce1c31f4d13adce21a3129 100644 (file)
@@ -656,7 +656,6 @@ static void chat_thread_start(int idx)
 
                                switch_threadattr_create(&thd_attr, chat_globals.pool);
                                switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-                               //switch_threadattr_priority_increase(thd_attr);
                                switch_thread_create(&chat_globals.msg_queue_thread[i], 
                                                                         thd_attr, 
                                                                         chat_thread_run,