From 28619fe71b30d0b2ac25dee5aed1e2f804283700 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 14 May 2021 01:59:20 +0200 Subject: [PATCH] Fix window process thread priorities While POSIX defines a single contiguous range of numbers that determine a thread's priority. Win32 defines priority classes and priority levels relative to these classes. pthread maps those to -15 .. +15 with the top six ones corresponding to REALTIME_PRIORITY_CLASS and max being THREAD_PRIORITY_TIME_CRITICAL Note that the PA backend can USE_MMCSS_THREAD_PRIORITIES and PBD::MMCSS::set_thread_characteristics() directly for the I/O threads. --- libs/pbd/pbd/pthread_utils.h | 12 +++++++++--- libs/pbd/pthread_utils.cc | 15 ++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/libs/pbd/pbd/pthread_utils.h b/libs/pbd/pbd/pthread_utils.h index 64c8ee551e..c6e809157a 100644 --- a/libs/pbd/pbd/pthread_utils.h +++ b/libs/pbd/pbd/pthread_utils.h @@ -54,9 +54,15 @@ /* these are relative to sched_get_priority_max() * see pbd_absolute_rt_priority() */ -#define PBD_RT_PRI_MAIN -20 -#define PBD_RT_PRI_MIDI -21 -#define PBD_RT_PRI_PROC -22 +#ifdef PLATFORM_WINDOWS +# define PBD_RT_PRI_MAIN -1 +# define PBD_RT_PRI_MIDI -2 +# define PBD_RT_PRI_PROC -2 +#else +# define PBD_RT_PRI_MAIN -20 +# define PBD_RT_PRI_MIDI -21 +# define PBD_RT_PRI_PROC -22 +#endif LIBPBD_API int pthread_create_and_store (std::string name, pthread_t *thread, void * (*start_routine)(void *), void * arg); LIBPBD_API void pthread_cancel_one (pthread_t thread); diff --git a/libs/pbd/pthread_utils.cc b/libs/pbd/pthread_utils.cc index dc948a00e8..78bf942171 100644 --- a/libs/pbd/pthread_utils.cc +++ b/libs/pbd/pthread_utils.cc @@ -288,18 +288,19 @@ pbd_absolute_rt_priority (int policy, int priority) /* use default. XXX this should be relative to audio (JACK) thread, * internal backends use -20 (Audio), -21 (MIDI), -22 (compuation) */ - priority = 7; // BaseUI backwards compat. - } - - if (priority > 0) { + priority = (p_min + p_max) / 2; + } else if (priority > 0) { priority += p_min; } else { - priority += p_max; + priority += p_max + 1; } - if (priority > p_max) + + if (priority > p_max) { priority = p_max; - if (priority < p_min) + } + if (priority < p_min) { priority = p_min; + } return priority; }