From f6e591de4ad42a773f15359f1fc9799b6c86615c Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Sat, 1 Mar 2014 14:36:34 -0600 Subject: [PATCH] windows only - add our own thread priority ability for core threads please test --- src/switch_apr.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/switch_apr.c b/src/switch_apr.c index 10f89f9c8e..7e8f04008c 100644 --- a/src/switch_apr.c +++ b/src/switch_apr.c @@ -618,12 +618,12 @@ struct apr_threadattr_t { int priority; }; #else -/* this needs to be revisited when apr for windows supports thread priority settings */ -/* search for WIN32 in this file */ +/* we are implementing our own windows support for thread priority settings because apr does not*/ struct apr_threadattr_t { apr_pool_t *pool; apr_int32_t detach; apr_size_t stacksize; + int priority; }; #endif @@ -633,9 +633,7 @@ SWITCH_DECLARE(switch_status_t) switch_threadattr_create(switch_threadattr_t ** switch_status_t status; if ((status = apr_threadattr_create(new_attr, pool)) == SWITCH_STATUS_SUCCESS) { -#ifndef WIN32 (*new_attr)->priority = SWITCH_PRI_LOW; -#endif } return status; @@ -653,9 +651,7 @@ SWITCH_DECLARE(switch_status_t) switch_threadattr_stacksize_set(switch_threadatt SWITCH_DECLARE(switch_status_t) switch_threadattr_priority_set(switch_threadattr_t *attr, switch_thread_priority_t priority) { -#ifndef WIN32 attr->priority = priority; -#endif return SWITCH_STATUS_SUCCESS; } @@ -664,8 +660,16 @@ static char TT_KEY[] = "1"; SWITCH_DECLARE(switch_status_t) switch_thread_create(switch_thread_t ** new_thread, switch_threadattr_t *attr, switch_thread_start_t func, void *data, switch_memory_pool_t *cont) { + apr_status_t status; + switch_core_memory_pool_set_data(cont, "_in_thread", TT_KEY); - return apr_thread_create(new_thread, attr, func, data, cont); + status = apr_thread_create(new_thread, attr, func, data, cont); +#ifdef WIN32 + if (attr->priority == SWITCH_PRI_REALTIME) { + SetThreadPriority(new_thread, THREAD_PRIORITY_HIGHEST); + } +#endif + return (switch_status_t)status; } /* socket stubs */