Skip to content

Commit fd77c90

Browse files
committed
ENH: change stop logic and convert hpi
1 parent c71494c commit fd77c90

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

applications/mne_scan/plugins/averaging/averaging.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ bool Averaging::start()
118118
bool Averaging::stop()
119119
{
120120
m_bProcessOutput = false;
121-
m_OutputProcessingThread.join();
121+
122+
if(m_OutputProcessingThread.joinable()){
123+
m_OutputProcessingThread.join();
124+
}
122125

123126
m_bPluginControlWidgetsInit = false;
124127

applications/mne_scan/plugins/covariance/covariance.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ bool Covariance::start()
168168

169169
bool Covariance::stop()
170170
{
171+
m_bProcessOutput = false;
172+
171173
if(m_OutputProcessingThread.joinable()){
172-
m_bProcessOutput = false;
173174
m_OutputProcessingThread.join();
174175
}
175176

applications/mne_scan/plugins/fiffsimulator/fiffsimulator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ bool FiffSimulator::start()
171171
bool FiffSimulator::stop()
172172
{
173173
// Stop this (consumer) thread first
174+
m_bProcessOutput = false;
175+
174176
if(m_OutputProcessingThread.joinable()){
175-
m_bProcessOutput = false;
176177
m_OutputProcessingThread.join();
177178
}
178179

applications/mne_scan/plugins/hpi/hpi.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ Hpi::Hpi()
105105

106106
Hpi::~Hpi()
107107
{
108-
if(isRunning()) {
109-
resetState();
108+
if(m_bProcessOutput) {
109+
stop();
110110
}
111111
}
112112

@@ -144,7 +144,9 @@ void Hpi::unload()
144144

145145
bool Hpi::start()
146146
{
147-
QThread::start();
147+
m_bProcessOutput = true;
148+
m_OutputProcessingThread = std::thread(&Hpi::run, this);
149+
148150

149151
return true;
150152
}
@@ -153,7 +155,11 @@ bool Hpi::start()
153155

154156
bool Hpi::stop()
155157
{
156-
requestInterruption();
158+
m_bProcessOutput = false;
159+
160+
if(m_OutputProcessingThread.joinable()){
161+
m_OutputProcessingThread.join();
162+
}
157163
resetState();
158164
return true;
159165
}
@@ -543,7 +549,7 @@ void Hpi::run()
543549
if(bFiffInfo) {
544550
break;
545551
}
546-
msleep(100);
552+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
547553
}
548554

549555
// init hpi fit
@@ -572,7 +578,7 @@ void Hpi::run()
572578

573579
MatrixXd matDataMerged(m_pFiffInfo->chs.size(), fittingWindowSize);
574580

575-
while(!isInterruptionRequested()) {
581+
while(m_bProcessOutput) {
576582
m_mutex.lock();
577583
if(fittingWindowSize != m_iFittingWindowSize) {
578584
fittingWindowSize = m_iFittingWindowSize;

applications/mne_scan/plugins/hpi/hpi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
#include <fiff/fiff_dig_point.h>
4949

50+
#include <thread>
51+
5052
//=============================================================================================================
5153
// QT INCLUDES
5254
//=============================================================================================================
@@ -320,6 +322,9 @@ class HPISHARED_EXPORT Hpi : public SCSHAREDLIB::AbstractAlgorithm
320322
SCSHAREDLIB::PluginInputData<SCMEASLIB::RealTimeMultiSampleArray>::SPtr m_pHpiInput; /**< The RealTimeMultiSampleArray of the Hpi input.*/
321323
SCSHAREDLIB::PluginOutputData<SCMEASLIB::RealTimeHpiResult>::SPtr m_pHpiOutput; /**< The RealTimeHpiResult of the Hpi output.*/
322324

325+
std::thread m_OutputProcessingThread;
326+
std::atomic_bool m_bProcessOutput;
327+
323328
signals:
324329
void errorsChanged(const QVector<double>& vErrors,
325330
double dMeanErrorDist);

0 commit comments

Comments
 (0)