Browse Source

Do not use RT threads for dummy engine / plugin testing

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.4.2
falkTX 3 years ago
parent
commit
2bbd787c42
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 32 additions and 18 deletions
  1. +8
    -1
      source/backend/engine/CarlaEngineDummy.cpp
  2. +20
    -16
      source/bridges-plugin/CarlaBridgePlugin.cpp
  3. +4
    -1
      source/utils/CarlaThread.hpp

+ 8
- 1
source/backend/engine/CarlaEngineDummy.cpp View File

@@ -212,7 +212,13 @@ protected:
const int64_t cycleTime = static_cast<int64_t>(
static_cast<double>(bufferSize) / pData->sampleRate * 1000000 + 0.5);

carla_stdout("CarlaEngineDummy audio thread started, cycle time: " P_INT64 "ms", cycleTime / 1000);
int delay = 0;
if (const char* const delaystr = std::getenv("CARLA_BRIDGE_DUMMY"))
if ((delay = atoi(delaystr)) == 1)
delay = 0;

carla_stdout("CarlaEngineDummy audio thread started, cycle time: " P_INT64 "ms, delay %ds",
cycleTime / 1000, delay);

float* audioIns[2] = {
(float*)std::malloc(sizeof(float)*bufferSize),
@@ -236,6 +242,7 @@ protected:

while (! shouldThreadExit())
{
carla_sleep(delay);
oldTime = getTimeInMicroseconds();

const PendingRtEventsRunner prt(this, bufferSize, true);


+ 20
- 16
source/bridges-plugin/CarlaBridgePlugin.cpp View File

@@ -585,6 +585,7 @@ int main(int argc, char* argv[])
// ---------------------------------------------------------------------
// Initialize OS features

const bool dummy = std::getenv("CARLA_BRIDGE_DUMMY") != nullptr;
const bool testing = std::getenv("CARLA_BRIDGE_TESTING") != nullptr;

#ifdef CARLA_OS_MAC
@@ -609,32 +610,35 @@ int main(int argc, char* argv[])
// ---------------------------------------------------------------------
// Set ourselves with high priority

#ifdef CARLA_OS_LINUX
// reset scheduler to normal mode
struct sched_param sparam;
carla_zeroStruct(sparam);
sched_setscheduler(0, SCHED_OTHER|SCHED_RESET_ON_FORK, &sparam);

// try niceness first, if it fails, try SCHED_RR
if (nice(-5) < 0)
if (!dummy && !testing)
{
sparam.sched_priority = (sched_get_priority_max(SCHED_RR) + sched_get_priority_min(SCHED_RR*7)) / 8;
#ifdef CARLA_OS_LINUX
// reset scheduler to normal mode
struct sched_param sparam;
carla_zeroStruct(sparam);
sched_setscheduler(0, SCHED_OTHER|SCHED_RESET_ON_FORK, &sparam);

if (sparam.sched_priority > 0)
// try niceness first, if it fails, try SCHED_RR
if (nice(-5) < 0)
{
if (sched_setscheduler(0, SCHED_RR|SCHED_RESET_ON_FORK, &sparam) < 0 && ! testing)
sparam.sched_priority = (sched_get_priority_max(SCHED_RR) + sched_get_priority_min(SCHED_RR*7)) / 8;

if (sparam.sched_priority > 0)
{
CarlaString error(std::strerror(errno));
carla_stderr("Failed to set high priority, error %i: %s", errno, error.buffer());
if (sched_setscheduler(0, SCHED_RR|SCHED_RESET_ON_FORK, &sparam) < 0)
{
CarlaString error(std::strerror(errno));
carla_stderr("Failed to set high priority, error %i: %s", errno, error.buffer());
}
}
}
}
#endif

#ifdef CARLA_OS_WIN
if (! SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS) && ! testing)
carla_stderr("Failed to set high priority.");
if (! SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS))
carla_stderr("Failed to set high priority.");
#endif
}

// ---------------------------------------------------------------------
// Listen for ctrl+c or sigint/sigterm events


+ 4
- 1
source/utils/CarlaThread.hpp View File

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

if (withRealtimePriority && std::getenv("CARLA_BRIDGE_DUMMY") != nullptr)
withRealtimePriority = false;

pthread_t handle;

pthread_attr_t attr;


Loading…
Cancel
Save