From f43510f2430150b7f425d614f6bc605fcd3ed0ce Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 19 Aug 2015 11:42:11 -0500 Subject: [PATCH] FS-7969 #resolve [Freeswitch segfaults due to pthread_setschedparam() on a thread that has exited] #comment please test this fix which was verified working --- libs/apr/.update | 2 +- .../include/arch/unix/apr_arch_threadproc.h | 1 + libs/apr/threadproc/unix/thread.c | 29 +++++++++++-------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libs/apr/.update b/libs/apr/.update index 1aeaab4078..6e6895295d 100644 --- a/libs/apr/.update +++ b/libs/apr/.update @@ -1 +1 @@ -Tue Aug 27 13:58:18 EDT 2013 +Wed Aug 19 11:38:49 CDT 2015 diff --git a/libs/apr/include/arch/unix/apr_arch_threadproc.h b/libs/apr/include/arch/unix/apr_arch_threadproc.h index bd9359a49f..348c6c55d3 100644 --- a/libs/apr/include/arch/unix/apr_arch_threadproc.h +++ b/libs/apr/include/arch/unix/apr_arch_threadproc.h @@ -55,6 +55,7 @@ struct apr_thread_t { void *data; apr_thread_start_t func; apr_status_t exitval; + int priority; }; struct apr_threadattr_t { diff --git a/libs/apr/threadproc/unix/thread.c b/libs/apr/threadproc/unix/thread.c index 8859e79ac7..165dddc238 100644 --- a/libs/apr/threadproc/unix/thread.c +++ b/libs/apr/threadproc/unix/thread.c @@ -135,6 +135,19 @@ APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr, static void *dummy_worker(void *opaque) { apr_thread_t *thread = (apr_thread_t*)opaque; + +#ifdef HAVE_PTHREAD_SETSCHEDPARAM + if (thread->priority) { + int policy; + struct sched_param param = { 0 }; + pthread_t tt = pthread_self(); + + pthread_getschedparam(tt, &policy, ¶m); + param.sched_priority = thread->priority; + pthread_setschedparam(tt, policy, ¶m); + } +#endif + return thread->func(thread, thread->data); } @@ -174,19 +187,11 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, return stat; } + if (attr && attr->priority) { + (*new)->priority = attr->priority; + } + if ((stat = pthread_create(&tt, temp, dummy_worker, (*new))) == 0) { - -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - if (attr && attr->priority) { - int policy; - struct sched_param param = { 0 }; - - pthread_getschedparam(tt, &policy, ¶m); - param.sched_priority = attr->priority; - pthread_setschedparam(tt, policy, ¶m); - } -#endif - *(*new)->td = tt; return APR_SUCCESS;