Harden cross thread code, and fix retriggering / busy check.

By actually looking at the result.
nix
Owen Green 6 years ago
parent 48dc167c1b
commit e5798aaa35

@ -20,6 +20,7 @@ under the European Unions Horizon 2020 research and innovation programme
#include <data/TensorTypes.hpp> #include <data/TensorTypes.hpp>
#include <FluidVersion.hpp> #include <FluidVersion.hpp>
#include <SC_PlugIn.hpp> #include <SC_PlugIn.hpp>
#include <atomic>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <string> #include <string>
@ -43,11 +44,12 @@ struct WrapperState
typename Client::ParamSetType params; typename Client::ParamSetType params;
Client client; Client client;
Node* mNode; Node* mNode;
bool mCancelled{false}; std::atomic<bool> mCancelled{false};
bool mJobDone{false}; std::atomic<bool> mJobDone{false};
bool mHasTriggered{false}; std::atomic<bool> mHasTriggered{false};
bool mSynchronous{false}; std::atomic<bool> mSynchronous{false};
bool mInNRT{false}; std::atomic<bool> mInNRT{false};
std::atomic<bool> mNodeAlive{true};
Result mResult{}; Result mResult{};
}; };
@ -341,7 +343,8 @@ public:
~NonRealTime() ~NonRealTime()
{ {
if (mWrapper->client().state() == ProcessState::kProcessing) auto state = mWrapper->client().state();
if (state == ProcessState::kProcessing)
{ {
std::cout << Wrapper::getName() << ": Processing cancelled" << std::endl; std::cout << Wrapper::getName() << ": Processing cancelled" << std::endl;
Wrapper::getInterfaceTable()->fSendNodeReply(&mParent->mNode, 1, "/done", Wrapper::getInterfaceTable()->fSendNodeReply(&mParent->mNode, 1, "/done",
@ -408,21 +411,29 @@ public:
if(!f->mData) return; if(!f->mData) return;
auto w = static_cast<SharedState*>(f->mData); auto w = static_cast<SharedState*>(f->mData);
SharedState& s = *w; SharedState& s = *w;
s->mInNRT = true;
s->mJobDone = false;
s->mCancelled = false;
Result result = validateParameters(s->params); Result result = validateParameters(s->params);
if (!result.ok()) if (!result.ok())
{ {
std::cout << "ERROR: " << Wrapper::getName() << ": " std::cout << "ERROR: " << Wrapper::getName() << ": "
<< result.message().c_str() << std::endl; << result.message().c_str() << std::endl;
s->mInNRT = false;
return; return;
} }
s->client.setSynchronous(s->mSynchronous); s->client.setSynchronous(s->mSynchronous);
s->client.enqueue(s->params); result = s->client.enqueue(s->params);
s->mResult = s->client.process(); if (!result.ok())
{
std::cout << "ERROR: " << Wrapper::getName() << ": "
<< result.message().c_str() << std::endl;
s->mInNRT = false;
return;
}
s->mJobDone = false;
s->mCancelled = false;
s->mHasTriggered = true; s->mHasTriggered = true;
s->mResult = s->client.process();
s->mInNRT = false; s->mInNRT = false;
w->~SharedState(); w->~SharedState();
f->mWorld->ft->fRTFree(f->mWorld,w); f->mWorld->ft->fRTFree(f->mWorld,w);
@ -483,8 +494,8 @@ public:
static bool exchangeBuffers(World* world, void* data) static bool exchangeBuffers(World* world, void* data)
{ {
if(!data) return false; if(!data) return false;
SharedState& s = *(static_cast<SharedState*>(data)); SharedState& s = *(static_cast<SharedState*>(data));
if(!s->mNodeAlive) return false;
s->params.template forEachParamType<BufferT, AssignBuffer>(world); s->params.template forEachParamType<BufferT, AssignBuffer>(world);
// At this point, we can see if we're finished and let the language know (or // At this point, we can see if we're finished and let the language know (or
// it can wait for the doneAction, but that takes extra time) use replyID to // it can wait for the doneAction, but that takes extra time) use replyID to
@ -1401,6 +1412,12 @@ public:
impl::FluidSCWrapperBase<Client>::init(); impl::FluidSCWrapperBase<Client>::init();
} }
~FluidSCWrapper()
{
mState->mNodeAlive = false;
}
std::shared_ptr<WrapperState<Client>>& state() { return mState; } std::shared_ptr<WrapperState<Client>>& state() { return mState; }

Loading…
Cancel
Save