diff options
author | Robin Gareus <robin@gareus.org> | 2018-10-11 01:47:46 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2018-10-11 15:29:50 +0200 |
commit | 78a3683233bc13e58badd7adb9b86995b81eb0c7 (patch) | |
tree | bc18d05867fbceac0f162fab5297b8f98c3daa48 /libs | |
parent | 3a776b58ceadbf7c7d9a1ab4f691f18e3306316a (diff) |
Consolidate relative sched_get_priority computation
Diffstat (limited to 'libs')
-rw-r--r-- | libs/pbd/pbd/pthread_utils.h | 1 | ||||
-rw-r--r-- | libs/pbd/pthread_utils.cc | 55 |
2 files changed, 29 insertions, 27 deletions
diff --git a/libs/pbd/pbd/pthread_utils.h b/libs/pbd/pbd/pthread_utils.h index e917fa27ce..f223d1c22e 100644 --- a/libs/pbd/pbd/pthread_utils.h +++ b/libs/pbd/pbd/pthread_utils.h @@ -60,6 +60,7 @@ LIBPBD_API int pbd_realtime_pthread_create ( void *(*start_routine) (void *), void *arg); +LIBPBD_API int pbd_absolute_rt_priority (int policy, int priority); LIBPBD_API int pbd_set_thread_priority (pthread_t, const int policy, int priority); LIBPBD_API bool pbd_mach_set_realtime_policy (pthread_t thread_id, double period_ns); diff --git a/libs/pbd/pthread_utils.cc b/libs/pbd/pthread_utils.cc index 118c54b97f..64ac8bb563 100644 --- a/libs/pbd/pthread_utils.cc +++ b/libs/pbd/pthread_utils.cc @@ -209,6 +209,32 @@ pthread_cancel_one (pthread_t thread) } int +pbd_absolute_rt_priority (int policy, int priority) +{ + /* POSIX requires a spread of at least 32 steps between min..max */ + const int p_min = sched_get_priority_min (policy); // Linux: 1 + const int p_max = sched_get_priority_max (policy); // Linux: 99 + + if (priority == 0) { + /* 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; + } else { + priority += p_max; + } + if (priority > p_max) priority = p_max; + if (priority < p_min) priority = p_min; + return priority; +} + + + +int pbd_realtime_pthread_create ( const int policy, int priority, const size_t stacksize, pthread_t *thread, @@ -220,12 +246,7 @@ pbd_realtime_pthread_create ( pthread_attr_t attr; struct sched_param parm; - const int p_min = sched_get_priority_min (policy); - const int p_max = sched_get_priority_max (policy); - priority += p_max; - if (priority > p_max) priority = p_max; - if (priority < p_min) priority = p_min; - parm.sched_priority = priority; + parm.sched_priority = pbd_absolute_rt_priority (policy, priority); pthread_attr_init (&attr); pthread_attr_setschedpolicy (&attr, policy); @@ -237,32 +258,12 @@ pbd_realtime_pthread_create ( pthread_attr_destroy (&attr); return rv; } - int pbd_set_thread_priority (pthread_t thread, const int policy, int priority) { struct sched_param param; memset (¶m, 0, sizeof (param)); - - /* POSIX requires a spread of at least 32 steps between min..max */ - const int p_min = sched_get_priority_min (policy); // Linux: 1 - const int p_max = sched_get_priority_max (policy); // Linux: 99 - - if (priority == 0) { - /* 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; - } else { - priority += p_max; - } - if (priority > p_max) priority = p_max; - if (priority < p_min) priority = p_min; - param.sched_priority = priority; + param.sched_priority = pbd_absolute_rt_priority (policy, priority); return pthread_setschedparam (thread, SCHED_FIFO, ¶m); } |