Stop horrible race condition by ensuring that only one thread-checking aync command is ever in progress

nix
Owen Green 6 years ago
parent fad43f18b2
commit 05f7c044b0

@ -194,8 +194,6 @@ public:
}); });
} }
/// Final input is the doneAction, not a param, so we skip it in the controlsIterator /// Final input is the doneAction, not a param, so we skip it in the controlsIterator
NonRealTime() : NonRealTime() :
mControlsIterator{mInBuf,static_cast<size_t>(static_cast<ptrdiff_t>(mNumInputs) - mSpecialIndex - 1)} mControlsIterator{mInBuf,static_cast<size_t>(static_cast<ptrdiff_t>(mNumInputs) - mSpecialIndex - 1)}
@ -210,7 +208,6 @@ public:
{ {
mFifoMsg.Set(mWorld, initNRTJob, nullptr, this); mFifoMsg.Set(mWorld, initNRTJob, nullptr, this);
mWorld->ft->fSendMsgFromRT(mWorld,mFifoMsg); mWorld->ft->fSendMsgFromRT(mWorld,mFifoMsg);
//we want to poll thread roughly every 20ms //we want to poll thread roughly every 20ms
checkThreadInterval = static_cast<size_t>(0.02 / controlDur()); checkThreadInterval = static_cast<size_t>(0.02 / controlDur());
set_calc_function<NonRealTime, &NonRealTime::poll>(); set_calc_function<NonRealTime, &NonRealTime::poll>();
@ -223,9 +220,10 @@ public:
if(0 == pollCounter++) if(0 == pollCounter++)
{ {
mWorld->ft->fDoAsynchronousCommand(mWorld, nullptr, Wrapper::getName(), this, mWorld->ft->fDoAsynchronousCommand(mWorld, nullptr, Wrapper::getName(), this,
postProcess, exchangeBuffers, tidyUp, destroy, postProcess, exchangeBuffers, tidyUp, destroy,
0, nullptr); 0, nullptr);
mCalcFunc = nop;
} }
pollCounter %= checkThreadInterval; pollCounter %= checkThreadInterval;
} }
@ -237,6 +235,7 @@ public:
{ {
auto w = static_cast<Wrapper*>(f->mData); auto w = static_cast<Wrapper*>(f->mData);
w->mDone = false; w->mDone = false;
Result result = validateParameters(w); Result result = validateParameters(w);
if (!result.ok()) if (!result.ok())
@ -270,9 +269,9 @@ public:
std::cout << "ERROR: " << Wrapper::getName() << ": " << r.message().c_str() << '\n'; std::cout << "ERROR: " << Wrapper::getName() << ": " << r.message().c_str() << '\n';
return false; return false;
} }
return true; return true;
} }
w->template set_calc_function<NonRealTime, &NonRealTime::poll>();
return false; return false;
} }
@ -288,7 +287,6 @@ public:
if(w->mDone && w->mNumInputs > 0) //don't check for doneAction if UGen has no ins if(w->mDone && w->mNumInputs > 0) //don't check for doneAction if UGen has no ins
{ {
int doneAction = static_cast<int>(w->in0(static_cast<int>(w->mNumInputs - 1))); //doneAction is last input; THIS IS THE LAW int doneAction = static_cast<int>(w->in0(static_cast<int>(w->mNumInputs - 1))); //doneAction is last input; THIS IS THE LAW
if(doneAction >= 2) w->mCalcFunc = nop;
world->ft->fDoneAction(doneAction,w); world->ft->fDoneAction(doneAction,w);
} }
} }

Loading…
Cancel
Save