From 467c801ce80b69abdb7efb4c23120532bed3fc96 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 29 Aug 2017 20:35:36 +0200 Subject: [PATCH] Abstract definition of rt-scheduler policy pthread-w32 does not support pthread_setschedparam() with SCHED_FIFO and bails out. While pthread_create() simply ignores the policy and sets the priority regadless. This only affects ctrl-surface event-loops & AutomationWatch on Windows. --- libs/ardour/automation_watch.cc | 2 +- libs/backends/alsa/alsa_audiobackend.cc | 4 ++-- libs/backends/alsa/alsa_midi.cc | 2 +- libs/backends/coreaudio/coreaudio_backend.cc | 2 +- libs/backends/portaudio/portaudio_backend.cc | 4 ++-- libs/backends/portaudio/winmmemidi_output_device.cc | 2 +- libs/pbd/pbd/base_ui.h | 3 ++- libs/pbd/pbd/pthread_utils.h | 13 +++++++++++++ 8 files changed, 23 insertions(+), 9 deletions(-) diff --git a/libs/ardour/automation_watch.cc b/libs/ardour/automation_watch.cc index c949509d09..ad05f3ac69 100644 --- a/libs/ardour/automation_watch.cc +++ b/libs/ardour/automation_watch.cc @@ -186,7 +186,7 @@ AutomationWatch::timer () void AutomationWatch::thread () { - pbd_set_thread_priority (pthread_self(), SCHED_FIFO, -25); + pbd_set_thread_priority (pthread_self(), PBD_SCHED_FIFO, -25); while (_run_thread) { Glib::usleep ((gulong) floor (Config->get_automation_interval_msecs() * 1000)); timer (); diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc index 9f42145314..525ff2e757 100644 --- a/libs/backends/alsa/alsa_audiobackend.cc +++ b/libs/backends/alsa/alsa_audiobackend.cc @@ -992,7 +992,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement) _run = true; _port_change_flag = false; - if (pbd_realtime_pthread_create (SCHED_FIFO, -20, 100000, + if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -20, 100000, &_main_thread, pthread_process, this)) { if (pthread_create (&_main_thread, NULL, pthread_process, this)) @@ -1129,7 +1129,7 @@ AlsaAudioBackend::create_process_thread (boost::function func) ThreadData* td = new ThreadData (this, func, stacksize); - if (pbd_realtime_pthread_create (SCHED_FIFO, -22, stacksize, + if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -22, stacksize, &thread_id, alsa_process_thread, td)) { pthread_attr_init (&attr); pthread_attr_setstacksize (&attr, stacksize); diff --git a/libs/backends/alsa/alsa_midi.cc b/libs/backends/alsa/alsa_midi.cc index 348586ad20..d593f73def 100644 --- a/libs/backends/alsa/alsa_midi.cc +++ b/libs/backends/alsa/alsa_midi.cc @@ -72,7 +72,7 @@ static void * pthread_process (void *arg) int AlsaMidiIO::start () { - if (pbd_realtime_pthread_create (SCHED_FIFO, -21, 100000, + if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -21, 100000, &_main_thread, pthread_process, this)) { if (pthread_create (&_main_thread, NULL, pthread_process, this)) { diff --git a/libs/backends/coreaudio/coreaudio_backend.cc b/libs/backends/coreaudio/coreaudio_backend.cc index 3e4a38e7a3..c4e11ef700 100644 --- a/libs/backends/coreaudio/coreaudio_backend.cc +++ b/libs/backends/coreaudio/coreaudio_backend.cc @@ -859,7 +859,7 @@ CoreAudioBackend::create_process_thread (boost::function func) ThreadData* td = new ThreadData (this, func, stacksize); - if (pbd_realtime_pthread_create (SCHED_FIFO, -22, stacksize, + if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -22, stacksize, &thread_id, coreaudio_process_thread, td)) { pthread_attr_init (&attr); pthread_attr_setstacksize (&attr, stacksize); diff --git a/libs/backends/portaudio/portaudio_backend.cc b/libs/backends/portaudio/portaudio_backend.cc index 3433ca3585..46e508fba7 100644 --- a/libs/backends/portaudio/portaudio_backend.cc +++ b/libs/backends/portaudio/portaudio_backend.cc @@ -787,7 +787,7 @@ PortAudioBackend::process_callback(const float* input, bool PortAudioBackend::start_blocking_process_thread () { - if (pbd_realtime_pthread_create (SCHED_FIFO, -20, 100000, + if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -20, 100000, &_main_blocking_thread, blocking_thread_func, this)) { if (pthread_create (&_main_blocking_thread, NULL, blocking_thread_func, this)) @@ -1115,7 +1115,7 @@ PortAudioBackend::create_process_thread (boost::function func) ThreadData* td = new ThreadData (this, func, stacksize); - if (pbd_realtime_pthread_create (SCHED_FIFO, -22, stacksize, + if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -22, stacksize, &thread_id, portaudio_process_thread, td)) { pthread_attr_init (&attr); pthread_attr_setstacksize (&attr, stacksize); diff --git a/libs/backends/portaudio/winmmemidi_output_device.cc b/libs/backends/portaudio/winmmemidi_output_device.cc index 25201af67b..72b1494ac5 100644 --- a/libs/backends/portaudio/winmmemidi_output_device.cc +++ b/libs/backends/portaudio/winmmemidi_output_device.cc @@ -230,7 +230,7 @@ WinMMEMidiOutputDevice::start_midi_output_thread () size_t stacksize = 100000; // TODO Use native threads - if (pbd_realtime_pthread_create (SCHED_FIFO, -21, stacksize, + if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -21, stacksize, &m_output_thread_handle, midi_output_thread, this)) { return false; } diff --git a/libs/pbd/pbd/base_ui.h b/libs/pbd/pbd/base_ui.h index b8569718ae..4d490fea5c 100644 --- a/libs/pbd/pbd/base_ui.h +++ b/libs/pbd/pbd/base_ui.h @@ -32,6 +32,7 @@ #include "pbd/libpbd_visibility.h" #include "pbd/crossthread.h" #include "pbd/event_loop.h" +#include "pbd/pthread_utils.h" /** A BaseUI is an abstraction designed to be used with any "user * interface" (not necessarily graphical) that needs to wait on @@ -91,7 +92,7 @@ class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop virtual void thread_init () {}; - int set_thread_priority (const int policy = SCHED_FIFO, int priority = 0) const; + int set_thread_priority (const int policy = PBD_SCHED_FIFO, int priority = 0) const; /** Called when there input ready on the request_channel */ diff --git a/libs/pbd/pbd/pthread_utils.h b/libs/pbd/pbd/pthread_utils.h index 2ef442caa5..a1660eb073 100644 --- a/libs/pbd/pbd/pthread_utils.h +++ b/libs/pbd/pbd/pthread_utils.h @@ -67,4 +67,17 @@ namespace PBD { LIBPBD_API extern PBD::Signal3 ThreadCreatedWithRequestSize; } +/* pthread-w32 does not support realtime scheduling + * (well, windows, doesn't..) and only supports SetThreadPriority() + * + * pthread_setschedparam() returns ENOTSUP if the policy is not SCHED_OTHER. + * + * however, pthread_create() with attributes, ignores the policy and + * only sets the priority (when PTHREAD_EXPLICIT_SCHED is used). + */ +#ifdef PLATFORM_WINDOWS +#define PBD_SCHED_FIFO SCHED_OTHER +#else +#define PBD_SCHED_FIFO SCHED_FIFO +#endif #endif /* __pbd_pthread_utils__ */ -- 2.30.2