improve a bit and add option

This commit is contained in:
tildearrow 2023-09-06 14:23:47 -05:00
parent e8dbacf6e0
commit 5329e551d4
7 changed files with 50 additions and 5 deletions

View file

@ -23,6 +23,7 @@
#include "engine.h"
#include "instrument.h"
#include "safeReader.h"
#include "workPool.h"
#include "../ta-log.h"
#include "../fileutils.h"
#ifdef HAVE_SDL2
@ -3123,6 +3124,10 @@ bool DivEngine::switchMaster(bool full) {
quitDispatch();
initDispatch();
}
if (renderPool!=NULL) {
delete renderPool;
renderPool=NULL;
}
if (initAudioBackend()) {
for (int i=0; i<song.systemLen; i++) {
disCont[i].setRates(got.rate);
@ -3314,6 +3319,7 @@ bool DivEngine::initAudioBackend() {
midiOutMode=getConfInt("midiOutMode",DIV_MIDI_MODE_NOTE);
if (metroVol<0.0f) metroVol=0.0f;
if (metroVol>2.0f) metroVol=2.0f;
renderPoolThreads=getConfInt("renderPoolThreads",0);
if (lowLatency) logI("using low latency mode.");

View file

@ -487,6 +487,7 @@ class DivEngine {
size_t totalProcessed;
unsigned int renderPoolThreads;
DivWorkPool* renderPool;
// MIDI stuff
@ -1264,6 +1265,8 @@ class DivEngine {
metroAmp(0.0f),
metroVol(1.0f),
totalProcessed(0),
renderPoolThreads(0),
renderPool(NULL),
curOrders(NULL),
curPat(NULL),
tempIns(NULL),

View file

@ -1790,8 +1790,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
std::chrono::steady_clock::time_point ts_processBegin=std::chrono::steady_clock::now();
if (renderPool==NULL) {
// TODO: test this
renderPool=new DivWorkPool(0);
renderPool=new DivWorkPool(renderPoolThreads);
}
// process MIDI events (TODO: everything)

View file

@ -43,11 +43,14 @@ void DivWorkThread::run() {
if (setFuckingPromise) {
parent->notify.set_value();
setFuckingPromise=false;
std::this_thread::yield();
}
if (terminate) {
break;
}
notify.wait(unique);
if (notify.wait_for(unique,std::chrono::milliseconds(100))==std::cv_status::timeout) {
logE("this task timed out!");
}
continue;
} else {
task=tasks.front();
@ -128,7 +131,6 @@ bool DivWorkPool::busy() {
void DivWorkPool::wait() {
if (!threaded) return;
//std::unique_lock<std::mutex> unique(selfLock);
if (busyCount==0) {
logV("nothing to do");
@ -141,6 +143,7 @@ void DivWorkPool::wait() {
for (unsigned int i=0; i<count; i++) {
workThreads[i].notify.notify_one();
}
std::this_thread::yield();
// wait
logV("waiting on future");

View file

@ -71,7 +71,6 @@ struct DivWorkThread {
*/
class DivWorkPool {
bool threaded;
std::mutex selfLock;
unsigned int count;
unsigned int pos;
DivWorkThread* workThreads;