13
0

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.
This commit is contained in:
Robin Gareus 2017-08-29 20:35:36 +02:00
parent df659e91f1
commit 467c801ce8
8 changed files with 23 additions and 9 deletions

View 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 ();

View 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);

View 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)) {

View 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);

View 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);

View 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;
}

View 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
*/

View 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__ */