Consolidate _realtime_pthread_create() into libpbd.
authorRobin Gareus <robin@gareus.org>
Tue, 29 Aug 2017 15:23:19 +0000 (17:23 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 29 Aug 2017 15:25:23 +0000 (17:25 +0200)
libs/backends/alsa/alsa_audiobackend.cc
libs/backends/alsa/alsa_midi.cc
libs/backends/alsa/rt_thread.h [deleted file]
libs/backends/coreaudio/coreaudio_backend.cc
libs/backends/coreaudio/rt_thread.h [deleted file]
libs/backends/portaudio/portaudio_backend.cc
libs/backends/portaudio/rt_thread.h [deleted file]
libs/backends/portaudio/winmmemidi_output_device.cc

index e7cdfedcb9c3862682b6c70a8616a6bafea2bc8f..9f4214531479cf6880da19c4aa1d28490372482d 100644 (file)
 #include <glibmm.h>
 
 #include "alsa_audiobackend.h"
-#include "rt_thread.h"
 
 #include "pbd/compose.h"
 #include "pbd/error.h"
 #include "pbd/file_utils.h"
+#include "pbd/pthread_utils.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/port_manager.h"
 #include "ardouralsautil/devicelist.h"
@@ -992,7 +992,7 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
        _run = true;
        _port_change_flag = false;
 
-       if (_realtime_pthread_create (SCHED_FIFO, -20, 100000,
+       if (pbd_realtime_pthread_create (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 (_realtime_pthread_create (SCHED_FIFO, -22, stacksize,
+       if (pbd_realtime_pthread_create (SCHED_FIFO, -22, stacksize,
                                &thread_id, alsa_process_thread, td)) {
                pthread_attr_init (&attr);
                pthread_attr_setstacksize (&attr, stacksize);
index 76738e9db5cb77b38bb0482a466f5fcca0923d98..348586ad202a7d1328f3391f76c1e40b05a6d836 100644 (file)
@@ -21,9 +21,9 @@
 #include <glibmm.h>
 
 #include "alsa_midi.h"
-#include "rt_thread.h"
 
 #include "pbd/error.h"
+#include "pbd/pthread_utils.h"
 #include "pbd/i18n.h"
 
 using namespace ARDOUR;
@@ -72,7 +72,7 @@ static void * pthread_process (void *arg)
 int
 AlsaMidiIO::start ()
 {
-       if (_realtime_pthread_create (SCHED_FIFO, -21, 100000,
+       if (pbd_realtime_pthread_create (SCHED_FIFO, -21, 100000,
                                &_main_thread, pthread_process, this))
        {
                if (pthread_create (&_main_thread, NULL, pthread_process, this)) {
diff --git a/libs/backends/alsa/rt_thread.h b/libs/backends/alsa/rt_thread.h
deleted file mode 100644 (file)
index 3d2efe2..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 Robin Gareus <robin@gareus.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __libbackend_alsa_rthread_h__
-#define __libbackend_alsa_rthread_h__
-
-#include <pthread.h>
-#include <sched.h>
-
-static int
-_realtime_pthread_create (
-               const int policy, int priority, const size_t stacksize,
-               pthread_t *thread,
-               void *(*start_routine) (void *),
-               void *arg)
-{
-       int rv;
-
-       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;
-
-       pthread_attr_init (&attr);
-       pthread_attr_setschedpolicy (&attr, policy);
-       pthread_attr_setschedparam (&attr, &parm);
-       pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
-       pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
-       pthread_attr_setstacksize (&attr, stacksize);
-       rv = pthread_create (thread, &attr, start_routine, arg);
-       pthread_attr_destroy (&attr);
-       return rv;
-}
-
-#endif
index f9dd15ea8dee9d5be9878cf20abaa2a96f8c2811..3e4a38e7a38740e4e499d99cf1596f9227e3b67c 100644 (file)
 #include <glibmm.h>
 
 #include "coreaudio_backend.h"
-#include "rt_thread.h"
 
 #include "pbd/compose.h"
 #include "pbd/error.h"
 #include "pbd/file_utils.h"
+#include "pbd/pthread_utils.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/port_manager.h"
 #include "pbd/i18n.h"
@@ -859,7 +859,7 @@ CoreAudioBackend::create_process_thread (boost::function<void()> func)
 
        ThreadData* td = new ThreadData (this, func, stacksize);
 
-       if (_realtime_pthread_create (SCHED_FIFO, -22, stacksize,
+       if (pbd_realtime_pthread_create (SCHED_FIFO, -22, stacksize,
                                      &thread_id, coreaudio_process_thread, td)) {
                pthread_attr_init (&attr);
                pthread_attr_setstacksize (&attr, stacksize);
diff --git a/libs/backends/coreaudio/rt_thread.h b/libs/backends/coreaudio/rt_thread.h
deleted file mode 100644 (file)
index 3d2efe2..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 Robin Gareus <robin@gareus.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __libbackend_alsa_rthread_h__
-#define __libbackend_alsa_rthread_h__
-
-#include <pthread.h>
-#include <sched.h>
-
-static int
-_realtime_pthread_create (
-               const int policy, int priority, const size_t stacksize,
-               pthread_t *thread,
-               void *(*start_routine) (void *),
-               void *arg)
-{
-       int rv;
-
-       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;
-
-       pthread_attr_init (&attr);
-       pthread_attr_setschedpolicy (&attr, policy);
-       pthread_attr_setschedparam (&attr, &parm);
-       pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
-       pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
-       pthread_attr_setstacksize (&attr, stacksize);
-       rv = pthread_create (thread, &attr, start_routine, arg);
-       pthread_attr_destroy (&attr);
-       return rv;
-}
-
-#endif
index 5bb8ecb08dd22a82ae919c5e880fd1b057737526..3433ca35853854a64200c44593910e34d9968937 100644 (file)
 #include <glibmm.h>
 
 #include "portaudio_backend.h"
-#include "rt_thread.h"
 
 #include "pbd/compose.h"
 #include "pbd/error.h"
 #include "pbd/file_utils.h"
+#include "pbd/pthread_utils.h"
 #include "pbd/windows_timer_utils.h"
 #include "pbd/windows_mmcss.h"
 
@@ -787,7 +787,7 @@ PortAudioBackend::process_callback(const float* input,
 bool
 PortAudioBackend::start_blocking_process_thread ()
 {
-       if (_realtime_pthread_create (SCHED_FIFO, -20, 100000,
+       if (pbd_realtime_pthread_create (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 (_realtime_pthread_create (SCHED_FIFO, -22, stacksize,
+       if (pbd_realtime_pthread_create (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/rt_thread.h b/libs/backends/portaudio/rt_thread.h
deleted file mode 100644 (file)
index 0535602..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2014 Robin Gareus <robin@gareus.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __libbackend_portaudio_rthread_h__
-#define __libbackend_portaudio_rthread_h__
-
-#include <pthread.h>
-#include <sched.h>
-
-static int
-_realtime_pthread_create (
-               const int policy, int priority, const size_t stacksize,
-               pthread_t *thread,
-               void *(*start_routine) (void *),
-               void *arg)
-{
-       int rv;
-
-       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;
-
-       pthread_attr_init (&attr);
-       pthread_attr_setschedpolicy (&attr, policy);
-       pthread_attr_setschedparam (&attr, &parm);
-       pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
-       pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
-       pthread_attr_setstacksize (&attr, stacksize);
-       rv = pthread_create (thread, &attr, start_routine, arg);
-       pthread_attr_destroy (&attr);
-       return rv;
-}
-
-#endif
index 2f6ad018958120e2cdfb6aa20c2b55c29e2b22d5..25201af67be0a5790e9a870177874781598b144d 100644 (file)
 
 #include "pbd/debug.h"
 #include "pbd/compose.h"
+#include "pbd/pthread_utils.h"
 #include "pbd/windows_timer_utils.h"
 #include "pbd/windows_mmcss.h"
 
-#include "rt_thread.h"
 #include "midi_util.h"
 
 #include "debug.h"
@@ -230,7 +230,7 @@ WinMMEMidiOutputDevice::start_midi_output_thread ()
        size_t stacksize = 100000;
 
        // TODO Use native threads
-       if (_realtime_pthread_create (SCHED_FIFO, -21, stacksize,
+       if (pbd_realtime_pthread_create (SCHED_FIFO, -21, stacksize,
                                &m_output_thread_handle, midi_output_thread, this)) {
                return false;
        }