From fad43f18b24cb1ea6dde325e29e4a5378c0b6889 Mon Sep 17 00:00:00 2001 From: Owen Green Date: Thu, 5 Sep 2019 14:11:24 +0100 Subject: [PATCH 1/2] wrapper: tidying --- include/FluidSCWrapper.hpp | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index cdfe8f5..cfb8bf9 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -219,26 +219,15 @@ public: /// The calc function. Checks to see if we've cancelled, spits out progress, launches tidy up when complete void poll(int) { -// if(!mClient.done()) -// { - out0(0) = static_cast(mClient.progress()); -// } -// else { - if(0 == pollCounter++) - { - mWorld->ft->fDoAsynchronousCommand(mWorld, nullptr, Wrapper::getName(), this, - postProcess, exchangeBuffers, tidyUp, destroy, - 0, nullptr); - } - - pollCounter %= checkThreadInterval; - -// if(mClient.state() == kDone) -// mDone = true; -// mCalcFunc = mWorld->ft->fClearUnitOutputs; -// if(!mDone) + out0(0) = static_cast(mClient.progress()); -// } + if(0 == pollCounter++) + { + mWorld->ft->fDoAsynchronousCommand(mWorld, nullptr, Wrapper::getName(), this, + postProcess, exchangeBuffers, tidyUp, destroy, + 0, nullptr); + } + pollCounter %= checkThreadInterval; } static void nop(Unit*, int) {} @@ -253,11 +242,8 @@ public: if (!result.ok()) { std::cout << "ERROR: " << Wrapper::getName() << ": " << result.message().c_str() << std::endl; -// w->mDone = true; return; } -// w->mClient.setSynchronous(mSynchronous); -// mClient.setQueu w->mClient.enqueue(w->mParams); w->mClient.process(); } @@ -311,8 +297,6 @@ public: { static_cast(unit)->mClient.cancel(); } - - private: static Result validateParameters(NonRealTime *w) From 05f7c044b0ba3d5f0037f44918493e4fedb63480 Mon Sep 17 00:00:00 2001 From: Owen Green Date: Thu, 5 Sep 2019 16:00:37 +0100 Subject: [PATCH 2/2] Stop horrible race condition by ensuring that only one thread-checking aync command is ever in progress --- include/FluidSCWrapper.hpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index cfb8bf9..8ca7dc3 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -194,8 +194,6 @@ public: }); } - - /// Final input is the doneAction, not a param, so we skip it in the controlsIterator NonRealTime() : mControlsIterator{mInBuf,static_cast(static_cast(mNumInputs) - mSpecialIndex - 1)} @@ -209,8 +207,7 @@ public: void init() { mFifoMsg.Set(mWorld, initNRTJob, nullptr, this); - mWorld->ft->fSendMsgFromRT(mWorld,mFifoMsg); - + mWorld->ft->fSendMsgFromRT(mWorld,mFifoMsg); //we want to poll thread roughly every 20ms checkThreadInterval = static_cast(0.02 / controlDur()); set_calc_function(); @@ -223,9 +220,10 @@ public: if(0 == pollCounter++) { - mWorld->ft->fDoAsynchronousCommand(mWorld, nullptr, Wrapper::getName(), this, - postProcess, exchangeBuffers, tidyUp, destroy, - 0, nullptr); + mWorld->ft->fDoAsynchronousCommand(mWorld, nullptr, Wrapper::getName(), this, + postProcess, exchangeBuffers, tidyUp, destroy, + 0, nullptr); + mCalcFunc = nop; } pollCounter %= checkThreadInterval; } @@ -237,6 +235,7 @@ public: { auto w = static_cast(f->mData); w->mDone = false; + Result result = validateParameters(w); if (!result.ok()) @@ -258,7 +257,7 @@ public: if(s==ProcessState::kDone || s==ProcessState::kDoneStillProcessing) { w->mDone = true; - + if(r.status() == Result::Status::kCancelled) { std::cout << Wrapper::getName() << ": Processing cancelled \n"; @@ -270,9 +269,9 @@ public: std::cout << "ERROR: " << Wrapper::getName() << ": " << r.message().c_str() << '\n'; return false; } - return true; } + w->template set_calc_function(); return false; } @@ -288,7 +287,6 @@ public: if(w->mDone && w->mNumInputs > 0) //don't check for doneAction if UGen has no ins { int doneAction = static_cast(w->in0(static_cast(w->mNumInputs - 1))); //doneAction is last input; THIS IS THE LAW - if(doneAction >= 2) w->mCalcFunc = nop; world->ft->fDoneAction(doneAction,w); } }