diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index bd19353991..671052ab30 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -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); /** diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 5f3a4fa258..f9d8476454 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -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) diff --git a/src/mod/applications/mod_callcenter/mod_callcenter.c b/src/mod/applications/mod_callcenter/mod_callcenter.c index df8670f2ee..e6f7ea7945 100644 --- a/src/mod/applications/mod_callcenter/mod_callcenter.c +++ b/src/mod/applications/mod_callcenter/mod_callcenter.c @@ -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); } diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index d84f3b6f7d..3acb7d6c55 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -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); diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c index 51677c5b3f..78eb57a20a 100644 --- a/src/mod/applications/mod_voicemail/mod_voicemail.c +++ b/src/mod/applications/mod_voicemail/mod_voicemail.c @@ -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); } diff --git a/src/mod/endpoints/mod_khomp/commons/base/system/freeswitch/thread.hpp b/src/mod/endpoints/mod_khomp/commons/base/system/freeswitch/thread.hpp index 9e5abc4372..3c61b6a6ec 100644 --- a/src/mod/endpoints/mod_khomp/commons/base/system/freeswitch/thread.hpp +++ b/src/mod/endpoints/mod_khomp/commons/base/system/freeswitch/thread.hpp @@ -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; diff --git a/src/mod/endpoints/mod_skypopen/mod_skypopen.c b/src/mod/endpoints/mod_skypopen/mod_skypopen.c index 43253a71e9..c3b5d81681 100644 --- a/src/mod/endpoints/mod_skypopen/mod_skypopen.c +++ b/src/mod/endpoints/mod_skypopen/mod_skypopen.c @@ -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) == diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 2793cd7354..3b5277647f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -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); } diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 045ea7a827..10d741bca4 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -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); } diff --git a/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c b/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c index 3e39e65407..81b0ef240f 100644 --- a/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c +++ b/src/mod/xml_int/mod_xml_scgi/mod_xml_scgi.c @@ -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); } diff --git a/src/switch_apr.c b/src/switch_apr.c index 49b7a9b5c5..64e066853e 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -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; } diff --git a/src/switch_core.c b/src/switch_core.c index 488b755232..1d87d9ce2e 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -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)) { diff --git a/src/switch_core_session.c b/src/switch_core_session.c index eb60968f5d..6e565dca06 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -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"); diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 2e3e71f204..556e3abab2 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -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"); diff --git a/src/switch_event.c b/src/switch_event.c index 175dadf5cf..02d23ee8f7 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -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); diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index d253a75bea..718572612e 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -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,