diff --git a/main/pbx.c b/main/pbx.c index 6aa3f5175747ed31346fd002ab4227ffa504b40d..a9ec90004d795bfd7e284452b6d934af08ae804c 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -40,6 +40,9 @@ #if defined(SOLARIS) #include <sys/loadavg.h> #endif +#include <sys/types.h> +#include <sched.h> +#include <string.h> #include "asterisk/lock.h" #include "asterisk/cli.h" @@ -4703,6 +4706,25 @@ static void *pbx_thread(void *data) PBX has finished running on the channel */ struct ast_channel *c = data; + int policy, priority_min, priority_max; + struct sched_param param = { .sched_priority = 0, }; + pthread_t thread = pthread_self(); + int tid = ast_get_tid(); + + // Change the thread schedule policy and priority + priority_min = sched_get_priority_min(SCHED_FIFO); + priority_max = sched_get_priority_max(SCHED_FIFO); + param.sched_priority = priority_max; + if (pthread_setschedparam(thread, SCHED_FIFO, ¶m) != 0) { + ast_log(LOG_ERROR, "pthread_setschedparam failed, %s\n", strerror(errno)); + } + // Get the new schedule policy and priority + policy = SCHED_FIFO - 1; + param.sched_priority = priority_min - 1; // set as an invalid value intentionally + if (pthread_getschedparam(thread, &policy, ¶m) != 0) { + ast_log(LOG_ERROR, "pthread_getschedparam failed, %s\n", strerror(errno)); + } + ast_verbose("thread entry is %s, tid=%d, new schedule policy=%d, priority=%d\n", __func__, tid, policy, param.sched_priority); __ast_pbx_run(c, NULL); decrease_call_count();