Browse Source

Set realtime priority for bridge audio threads

tags/1.9.8
falkTX 8 years ago
parent
commit
56fc869a48
3 changed files with 44 additions and 19 deletions
  1. +1
    -2
      source/backend/engine/CarlaEngineBridge.cpp
  2. +2
    -3
      source/libjack/libjack.cpp
  3. +41
    -14
      source/utils/CarlaThread.hpp

+ 1
- 2
source/backend/engine/CarlaEngineBridge.cpp View File

@@ -215,8 +215,7 @@ public:
fShmNonRtServerControl.commitWrite(); fShmNonRtServerControl.commitWrite();
} }


// TODO
startThread(/*Thread::realtimeAudioPriority*/);
startThread(true);
return true; return true;
} }




+ 2
- 3
source/libjack/libjack.cpp View File

@@ -168,7 +168,7 @@ public:
jack_carla_interposed_action(1, fSetupHints, (void*)carla_interposed_callback); jack_carla_interposed_action(1, fSetupHints, (void*)carla_interposed_callback);
jack_carla_interposed_action(2, fSessionManager, nullptr); jack_carla_interposed_action(2, fSessionManager, nullptr);


fNonRealtimeThread.startThread();
fNonRealtimeThread.startThread(false);
} }


~CarlaJackAppClient() noexcept override ~CarlaJackAppClient() noexcept override
@@ -1024,8 +1024,7 @@ void CarlaJackAppClient::runNonRealtimeThread()
fMidiOutBuffers[i].isInput = false; fMidiOutBuffers[i].isInput = false;
} }


// TODO
fRealtimeThread.startThread(/*Thread::realtimeAudioPriority*/);
fRealtimeThread.startThread(true);


fLastPingTime = getCurrentTimeMilliseconds(); fLastPingTime = getCurrentTimeMilliseconds();
carla_stdout("Carla Jack Client Ready!"); carla_stdout("Carla Jack Client Ready!");


+ 41
- 14
source/utils/CarlaThread.hpp View File

@@ -86,33 +86,60 @@ public:
/* /*
* Start the thread. * Start the thread.
*/ */
bool startThread() noexcept
bool startThread(const bool withRealtimePriority = false) noexcept
{ {
// check if already running // check if already running
CARLA_SAFE_ASSERT_RETURN(! isThreadRunning(), true); CARLA_SAFE_ASSERT_RETURN(! isThreadRunning(), true);


pthread_t handle;

pthread_attr_t attr;
pthread_attr_init(&attr);

struct sched_param sched_param;
carla_zeroStruct(sched_param);

if (withRealtimePriority)
{
sched_param.sched_priority = 80;

if (pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0 &&
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0 &&
#ifndef CARLA_OS_WIN
(pthread_attr_setschedpolicy(&attr, SCHED_FIFO) == 0 ||
pthread_attr_setschedpolicy(&attr, SCHED_RR) == 0) &&
#endif
pthread_attr_setschedparam(&attr, &sched_param) == 0)
{
carla_stdout("CarlaThread with realtime priority successful");
}
else
{
carla_stdout("CarlaThread with realtime priority failed, going with normal priority instead");
pthread_attr_destroy(&attr);
pthread_attr_init(&attr);
}
}

const CarlaMutexLocker cml(fLock); const CarlaMutexLocker cml(fLock);


fShouldExit = false; fShouldExit = false;


pthread_t handle;
const bool ok = pthread_create(&handle, &attr, _entryPoint, this) == 0;
pthread_attr_destroy(&attr);


if (pthread_create(&handle, nullptr, _entryPoint, this) == 0)
{
CARLA_SAFE_ASSERT_RETURN(ok, false);
#ifdef PTW32_DLLPORT #ifdef PTW32_DLLPORT
CARLA_SAFE_ASSERT_RETURN(handle.p != nullptr, false);
CARLA_SAFE_ASSERT_RETURN(handle.p != nullptr, false);
#else #else
CARLA_SAFE_ASSERT_RETURN(handle != 0, false);
CARLA_SAFE_ASSERT_RETURN(handle != 0, false);
#endif #endif
pthread_detach(handle);
_copyFrom(handle);

// wait for thread to start
fSignal.wait();
return true;
}
pthread_detach(handle);
_copyFrom(handle);


return false;
// wait for thread to start
fSignal.wait();
return true;
} }


/* /*


Loading…
Cancel
Save