Skip to content

Commit 461d4a5

Browse files
committed
ENH: convert averaging plugin
1 parent 224ffc2 commit 461d4a5

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

applications/mne_scan/plugins/averaging/averaging.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ using namespace Eigen;
7777

7878
Averaging::Averaging()
7979
: m_pCircularBuffer(CircularBuffer<FIFFLIB::FiffEvokedSet>::SPtr::create(40))
80+
, m_bProcessOutput(false)
8081
{
8182
}
8283

8384
//=============================================================================================================
8485

8586
Averaging::~Averaging()
8687
{
87-
if(this->isRunning())
88+
if(m_OutputProcessingThread.joinable())
8889
stop();
8990
}
9091

@@ -106,17 +107,18 @@ void Averaging::unload()
106107

107108
bool Averaging::start()
108109
{
109-
QThread::start();
110+
m_bProcessOutput = true;
111+
m_OutputProcessingThread = std::thread(&Averaging::run, this);
110112

111113
return true;
112114
}
113115

114116
//=============================================================================================================
115117

116118
bool Averaging::stop()
117-
{
118-
requestInterruption();
119-
wait(500);
119+
{
120+
m_bProcessOutput = false;
121+
m_OutputProcessingThread.join();
120122

121123
m_bPluginControlWidgetsInit = false;
122124

@@ -406,7 +408,7 @@ void Averaging::onChangeBaselineActive(bool state)
406408
void Averaging::onNewEvokedSet(const FIFFLIB::FiffEvokedSet& evokedSet,
407409
const QStringList& lResponsibleTriggerTypes)
408410
{
409-
if(!this->isRunning()) {
411+
if(!m_bProcessOutput) {
410412
return;
411413
}
412414

@@ -439,7 +441,7 @@ void Averaging::run()
439441
FIFFLIB::FiffEvokedSet evokedSet;
440442
QStringList lResponsibleTriggerTypes;
441443

442-
while(!isInterruptionRequested()){
444+
while(m_bProcessOutput){
443445
if(m_pCircularBuffer->pop(evokedSet)) {
444446
m_qMutex.lock();
445447
lResponsibleTriggerTypes = m_lResponsibleTriggerTypes;

applications/mne_scan/plugins/averaging/averaging.h

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

4848
#include <fiff/fiff_evoked_set.h>
4949

50+
#include <thread>
51+
5052
//=============================================================================================================
5153
// QT INCLUDES
5254
//=============================================================================================================
@@ -237,6 +239,9 @@ class AVERAGINGSHARED_EXPORT Averaging : public SCSHAREDLIB::AbstractAlgorithm
237239

238240
QMap<QString,int> m_mapStimChsIndexNames; /**< The currently available stim channels and their corresponding index in the data. */
239241

242+
std::thread m_OutputProcessingThread;
243+
std::atomic_bool m_bProcessOutput;
244+
240245
signals:
241246
void stimChannelsChanged(const QMap<QString,int>& mapStimChsIndexNames);
242247
void fiffChInfoChanged(const QList<FIFFLIB::FiffChInfo>& fiffChInfoList);

0 commit comments

Comments
 (0)