Abstract definition of rt-scheduler policy
authorRobin Gareus <robin@gareus.org>
Tue, 29 Aug 2017 18:35:36 +0000 (20:35 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 29 Aug 2017 18:35:36 +0000 (20:35 +0200)
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
libs/backends/alsa/alsa_audiobackend.cc
libs/backends/alsa/alsa_midi.cc
libs/backends/coreaudio/coreaudio_backend.cc
libs/backends/portaudio/portaudio_backend.cc
libs/backends/portaudio/winmmemidi_output_device.cc
libs/pbd/pbd/base_ui.h
libs/pbd/pbd/pthread_utils.h

index c949509d091e88348cdf8bdb8801fec4e33214f3..ad05f3ac69b8db0bfac805a30d58dd39f85e6735 100644 (file)
@@ -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 ();
index 9f4214531479cf6880da19c4aa1d28490372482d..525ff2e75733db04b4a03e0a46a11aeb909f4568 100644 (file)
@@ -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<void()> 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);
index 348586ad202a7d1328f3391f76c1e40b05a6d836..d593f73def1768df8f0631ae281731ead3d793c1 100644 (file)
@@ -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)) {
index 3e4a38e7a38740e4e499d99cf1596f9227e3b67c..c4e11ef7002aa6ca6222edd501e578706e4c81c5 100644 (file)
@@ -859,7 +859,7 @@ CoreAudioBackend::create_process_thread (boost::function<void()> 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);
index 3433ca35853854a64200c44593910e34d9968937..46e508fba71f497e450e3f39820d07861f7c2fdd 100644 (file)
@@ -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<void()> 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);
index 25201af67be0a5790e9a870177874781598b144d..72b1494ac5468068072fd3d511299a3583689836 100644 (file)
@@ -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;
        }
index b8569718aeaa35301d83f12d4b2d298b91ea211f..4d490fea5c401f390442a06014d5d7c5fecce25b 100644 (file)
@@ -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
         */
index 2ef442caa5103bd4207ef4a082d46d1d2c148171..a1660eb073d4ef9b6a518e9d6ab6cc2d1f01f4d9 100644 (file)
@@ -67,4 +67,17 @@ namespace PBD {
        LIBPBD_API extern PBD::Signal3<void,pthread_t,std::string,uint32_t> 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__ */