Skip to content

Commit

Permalink
Extra thread sanitation efforts
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Sep 21, 2023
1 parent 7029781 commit 1e25f61
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ using namespace complex;
class FindNeighborhoodsImpl
{
public:
FindNeighborhoodsImpl(FindNeighborhoods* filter, usize totalFeatures, const std::vector<int64_t>& bins, const std::vector<float>& criticalDistance)
FindNeighborhoodsImpl(FindNeighborhoods* filter, usize totalFeatures, const std::vector<int64_t>& bins, const std::vector<float>& criticalDistance, const std::atomic_bool& shouldCancel)
: m_Filter(filter)
, m_TotalFeatures(totalFeatures)
, m_Bins(bins)
, m_CriticalDistance(criticalDistance)
, m_ShouldCancel(shouldCancel)
{
}

Expand Down Expand Up @@ -48,10 +49,12 @@ class FindNeighborhoodsImpl
startTime = now;
}
}
if(m_Filter->getCancel())

if(m_ShouldCancel)
{
break;
return;
}

bin1x = m_Bins[3 * featureIdx];
bin1y = m_Bins[3 * featureIdx + 1];
bin1z = m_Bins[3 * featureIdx + 2];
Expand Down Expand Up @@ -92,6 +95,7 @@ class FindNeighborhoodsImpl
usize m_TotalFeatures = 0;
const std::vector<int64>& m_Bins;
const std::vector<float32>& m_CriticalDistance;
const std::atomic_bool& m_ShouldCancel;
};

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -185,7 +189,7 @@ Result<> FindNeighborhoods::operator()()
ParallelDataAlgorithm parallelAlgorithm;
parallelAlgorithm.setRange(Range(0, totalFeatures));
parallelAlgorithm.setParallelizationEnabled(true);
parallelAlgorithm.execute(FindNeighborhoodsImpl(this, totalFeatures, bins, criticalDistance));
parallelAlgorithm.execute(FindNeighborhoodsImpl(this, totalFeatures, bins, criticalDistance, m_ShouldCancel));

// Output Variables
auto& outputNeighborList = m_DataStructure.getDataRefAs<NeighborList<int32_t>>(m_InputValues->NeighborhoodListArrayName);
Expand Down

0 comments on commit 1e25f61

Please sign in to comment.