Skip to content

Commit

Permalink
Introduce stricter ordering for access to mDone atomic in NRT wrapper (
Browse files Browse the repository at this point in the history
…#30)

This works perfectly
  • Loading branch information
weefuzzy authored Nov 4, 2021
1 parent 11f9423 commit e5c75cf
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions include/wrapper/NonRealtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class NonRealTime : public SCUnit
auto& ar = *args;
if (auto ptr = get(NRTCommand::mID).lock())
{
ptr->mDone.store(false, std::memory_order_relaxed);
ptr->mDone.store(false, std::memory_order_release);
mParams.template setParameterValuesRT<ParamsFromOSC>(nullptr, world,
ar);
mSynchronous = static_cast<bool>(ar.geti());
Expand Down Expand Up @@ -397,13 +397,13 @@ class NonRealTime : public SCUnit

if (result.status() != Result::Status::kError)
{
ptr->mDone.store(false, std::memory_order_relaxed);
ptr->mDone.store(false, std::memory_order_release);
mResult = client.process();
Wrapper::printResult(world, mResult);

bool error = mResult.status() == Result::Status::kError;

if (error) ptr->mDone.store(true, std::memory_order_relaxed);
if (error) ptr->mDone.store(true, std::memory_order_release);
bool toStage3 = mSynchronous && !error;
return toStage3;
}
Expand Down Expand Up @@ -439,7 +439,7 @@ class NonRealTime : public SCUnit
if (NRTCommand::mID >= 0 && mSynchronous)
NRTCommand::sendReply(name(),
mResult.status() != Result::Status::kError);
ptr->mDone.store(true, std::memory_order_relaxed);
ptr->mDone.store(true, std::memory_order_release);
return true;
}
return false;
Expand Down Expand Up @@ -489,7 +489,7 @@ class NonRealTime : public SCUnit
{
std::cout << Wrapper::getName() << ": Processing cancelled"
<< std::endl;
ptr->mDone.store(true, std::memory_order_relaxed);
ptr->mDone.store(true, std::memory_order_release);
return false;
}

Expand All @@ -498,7 +498,7 @@ class NonRealTime : public SCUnit
Wrapper::printResult(world, r);
if (!mSuccess)
{
ptr->mDone.store(true, std::memory_order_relaxed);
ptr->mDone.store(true, std::memory_order_release);
return false;
}
// if we're progressing to stage3, don't unlock the lock just yet
Expand Down Expand Up @@ -530,7 +530,7 @@ class NonRealTime : public SCUnit
NRTCommand::sendReply(name(), mSuccess);
}

ptr->mDone.store(true, std::memory_order_relaxed); // = true;
ptr->mDone.store(true, std::memory_order_release); // = true;
return true;
}
std::cout << "ERROR: Failed to lock\n";
Expand Down Expand Up @@ -826,7 +826,7 @@ class NonRealTime : public SCUnit
if (auto ptr = mRecord.lock())
{
mInit = true;
mDone = ptr->mDone.load(std::memory_order_relaxed);
mDone = ptr->mDone.load(std::memory_order_acquire);
out0(0) = static_cast<float>(ptr->mClient.progress());
}
else
Expand Down Expand Up @@ -940,7 +940,7 @@ class NonRealTime : public SCUnit
{
mInit = true;
auto& client = ptr->mClient;
mDone = ptr->mDone.load(std::memory_order_relaxed);
mDone = ptr->mDone.load(std::memory_order_acquire);
out0(0) = mDone ? 1 : static_cast<float>(client.progress());
}
else
Expand Down

0 comments on commit e5c75cf

Please sign in to comment.