| 1382 | |
| 1383 | |
| 1384 | static void Engine_fallbackRun(Engine* that) { |
| 1385 | system::setThreadName("Engine fallback"); |
| 1386 | contextSet(that->internal->context); |
| 1387 | |
| 1388 | while (that->internal->fallbackRunning) { |
| 1389 | if (!that->getMasterModule()) { |
| 1390 | // Step blocks and wait |
| 1391 | double start = system::getTime(); |
| 1392 | int frames = std::floor(that->getSampleRate() / 60); |
| 1393 | that->stepBlock(frames); |
| 1394 | double end = system::getTime(); |
| 1395 | |
| 1396 | double duration = frames * that->getSampleTime() - (end - start); |
| 1397 | if (duration > 0.0) { |
| 1398 | std::this_thread::sleep_for(std::chrono::duration<double>(duration)); |
| 1399 | } |
| 1400 | } |
| 1401 | else { |
| 1402 | // Wait for master module to be unset, or for the request to stop running |
| 1403 | std::unique_lock<std::mutex> lock(that->internal->fallbackMutex); |
| 1404 | that->internal->fallbackCv.wait(lock, [&]() { |
| 1405 | return !that->internal->fallbackRunning || !that->getMasterModule(); |
| 1406 | }); |
| 1407 | } |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | |
| 1412 | void Engine::startFallbackThread() { |
nothing calls this directly
no test coverage detected