Skip to content

Commit 227aec5

Browse files
committed
Add more thread safety
1 parent 5ac5a12 commit 227aec5

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

Source/Plugins/SpikeSorter/SpikeSortBoxes.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ void SpikeSortBoxes::projectOnPrincipalComponents(SorterSpikePtr so)
884884
bPCAJobSubmitted = true;
885885
bRePCA = false;
886886
// submit a new job to compute the spike buffer.
887-
PCAJobPtr job = new PCAjob(spikeBuffer,pc1,pc2, &pc1min, &pc2min, &pc1max, &pc2max, bPCAjobFinished);
887+
PCAJobPtr job = new PCAjob(spikeBuffer,pc1,pc2, pc1min, pc2min, pc1max, pc2max, bPCAjobFinished);
888888
computingThread->addPCAjob(job);
889889
}
890890
}
@@ -1706,15 +1706,13 @@ static double sqrarg;
17061706
#define SQR(a) ((sqrarg = (a)) == 0.0 ? 0.0 : sqrarg * sqrarg)
17071707

17081708
PCAjob::PCAjob(SorterSpikeArray& _spikes, float* _pc1, float* _pc2,
1709-
float* pc1Min, float* pc2Min, float* pc1Max, float* pc2Max, std::atomic<bool>& _reportDone) : spikes(_spikes), reportDone(_reportDone)
1709+
std::atomic<float>& pc1Min, std::atomic<float>& pc2Min, std::atomic<float>&pc1Max, std::atomic<float>& pc2Max, std::atomic<bool>& _reportDone) : spikes(_spikes),
1710+
pc1min(pc1Min), pc2min(pc2Min), pc1max(pc1Max), pc2max(pc2Max), reportDone(_reportDone)
17101711
{
17111712
cov = nullptr;
17121713
pc1 = _pc1;
17131714
pc2 = _pc2;
1714-
pc1min = pc1Min;
1715-
pc2min = pc2Min;
1716-
pc1max = pc1Max;
1717-
pc2max = pc2Max;
1715+
17181716
dim = spikes[0]->getChannel()->getNumChannels()*spikes[0]->getChannel()->getTotalSamples();
17191717

17201718
};
@@ -2114,10 +2112,10 @@ void PCAjob::computeSVD()
21142112
}
21152113

21162114

2117-
*pc1min = min1 - 1.5 * (max1-min1);
2118-
*pc2min = min2 - 1.5 * (max2-min2);
2119-
*pc1max = max1 + 1.5 * (max1-min1);
2120-
*pc2max = max2 + 1.5 * (max2-min2);
2115+
pc1min = min1 - 1.5 * (max1-min1);
2116+
pc2min = min2 - 1.5 * (max2-min2);
2117+
pc1max = max1 + 1.5 * (max1-min1);
2118+
pc2max = max2 + 1.5 * (max2-min2);
21212119

21222120
// clear memory
21232121
for (int k = 0; k < dim; k++)

Source/Plugins/SpikeSorter/SpikeSortBoxes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ class PCAjob : public ReferenceCountedObject
181181
{
182182
public:
183183
PCAjob(SorterSpikeArray& _spikes, float* _pc1, float* _pc2,
184-
float*, float*, float*, float*, std::atomic<bool>& _reportDone);
184+
std::atomic<float>&, std::atomic<float>&, std::atomic<float>&, std::atomic<float>&, std::atomic<bool>& _reportDone);
185185
~PCAjob();
186186
void computeCov();
187187
void computeSVD();
188188

189189
float** cov;
190190
SorterSpikeArray spikes;
191191
float* pc1, *pc2;
192-
float* pc1min, *pc2min, *pc1max, *pc2max;
192+
std::atomic<float>& pc1min, &pc2min, &pc1max, &pc2max;
193193
std::atomic<bool>& reportDone;
194194
private:
195195
int svdcmp(float** a, int nRows, int nCols, float* w, float** v);
@@ -302,7 +302,7 @@ class SpikeSortBoxes
302302
std::vector<BoxUnit> boxUnits;
303303
std::vector<PCAUnit> pcaUnits;
304304
float* pc1, *pc2;
305-
float pc1min, pc2min, pc1max, pc2max;
305+
std::atomic<float> pc1min, pc2min, pc1max, pc2max;
306306
SorterSpikeArray spikeBuffer;
307307
int bufferSize,spikeBufferIndex;
308308
PCAcomputingThread* computingThread;

0 commit comments

Comments
 (0)