[Major] Scalar cannot be put in Thread, becuase it update QLineEdit of the MainThread and it is not thread-safe
This commit is contained in:
parent
dfdc5c4700
commit
3b3a22382b
|
@ -111,34 +111,34 @@ private:
|
|||
};
|
||||
|
||||
//^#======================================================= Timing Thread
|
||||
// class TimingThread : public QThread {
|
||||
// Q_OBJECT
|
||||
// public:
|
||||
// TimingThread(QObject * parent = 0 ) : QThread(parent){
|
||||
// waitTime = 20; // multiple of 100 mili sec
|
||||
// stop = false;
|
||||
// }
|
||||
// bool isStopped() const {return stop;}
|
||||
// void Stop() { this->stop = true;}
|
||||
// void SetWaitTimeinSec(float sec) {waitTime = sec * 10 ;}
|
||||
// float GetWaitTimeinSec() const {return waitTime/10.;}
|
||||
// void DoOnce() {emit timeUp();};
|
||||
// void run(){
|
||||
// unsigned int count = 0;
|
||||
// stop = false;
|
||||
// do{
|
||||
// usleep(100000);
|
||||
// count ++;
|
||||
// if( count % waitTime == 0){
|
||||
// emit timeUp();
|
||||
// }
|
||||
// }while(!stop);
|
||||
// }
|
||||
// signals:
|
||||
// void timeUp();
|
||||
// private:
|
||||
// bool stop;
|
||||
// unsigned int waitTime;
|
||||
// };
|
||||
class TimingThread : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TimingThread(QObject * parent = 0 ) : QThread(parent){
|
||||
waitTime = 20; // multiple of 100 mili sec
|
||||
stop = false;
|
||||
}
|
||||
bool isStopped() const {return stop;}
|
||||
void Stop() { this->stop = true;}
|
||||
void SetWaitTimeinSec(float sec) {waitTime = sec * 10 ;}
|
||||
float GetWaitTimeinSec() const {return waitTime/10.;}
|
||||
void DoOnce() {emit timeUp();};
|
||||
void run(){
|
||||
unsigned int count = 0;
|
||||
stop = false;
|
||||
do{
|
||||
usleep(100000);
|
||||
count ++;
|
||||
if( count % waitTime == 0){
|
||||
emit timeUp();
|
||||
}
|
||||
}while(!stop);
|
||||
}
|
||||
signals:
|
||||
void timeUp();
|
||||
private:
|
||||
bool stop;
|
||||
unsigned int waitTime;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
69
FSUDAQ.cpp
69
FSUDAQ.cpp
|
@ -309,11 +309,14 @@ FSUDAQ::FSUDAQ(QWidget *parent) : QMainWindow(parent){
|
|||
FSUDAQ::~FSUDAQ(){
|
||||
DebugPrint("%s", "FSUDAQ");
|
||||
if( scalar ) {
|
||||
scalarTimer->stop();
|
||||
if( scalarThread->isRunning() ){
|
||||
scalarThread->quit();
|
||||
scalarThread->exit();
|
||||
}
|
||||
scalarTimingThread->Stop();
|
||||
scalarTimingThread->quit();
|
||||
scalarTimingThread->exit();
|
||||
// scalarTimer->stop();
|
||||
// if( scalarThread->isRunning() ){
|
||||
// scalarThread->quit();
|
||||
// scalarThread->exit();
|
||||
// }
|
||||
CleanUpScalar();
|
||||
//don't need to delete scalar, it is managed by this
|
||||
}
|
||||
|
@ -762,10 +765,15 @@ void FSUDAQ::CloseDigitizers(){
|
|||
scope = nullptr;
|
||||
}
|
||||
|
||||
scalarTimer->stop();
|
||||
if( scalarThread->isRunning() ){
|
||||
scalarThread->quit();
|
||||
scalarThread->exit();
|
||||
// scalarTimer->stop();
|
||||
// if( scalarThread->isRunning() ){
|
||||
// scalarThread->quit();
|
||||
// scalarThread->exit();
|
||||
// }
|
||||
scalarTimingThread->Stop();
|
||||
if( scalarTimingThread->isRunning() ){
|
||||
scalarTimingThread->quit();
|
||||
scalarTimingThread->exit();
|
||||
}
|
||||
if( scalar ) CleanUpScalar();
|
||||
|
||||
|
@ -870,18 +878,18 @@ void FSUDAQ::SetupScalar(){
|
|||
lbScalarACQStatus = nullptr;
|
||||
lbTotalFileSize = nullptr;
|
||||
|
||||
// scalarThread = new TimingThread(scalar);
|
||||
// scalarThread->SetWaitTimeinSec(1.0);
|
||||
// connect(scalarThread, &TimingThread::timeUp, this, &FSUDAQ::UpdateScalar);
|
||||
scalarTimingThread = new TimingThread(scalar);
|
||||
scalarTimingThread->SetWaitTimeinSec(ScalarUpdateinMiliSec / 1000.);
|
||||
connect(scalarTimingThread, &TimingThread::timeUp, this, &FSUDAQ::UpdateScalar);
|
||||
|
||||
scalarThread = new QThread(this);
|
||||
scalarWorker = new ScalarWorker(this);
|
||||
scalarWorker->moveToThread(scalarThread);
|
||||
// scalarThread = new QThread(this);
|
||||
// scalarWorker = new ScalarWorker(this);
|
||||
// scalarWorker->moveToThread(scalarThread);
|
||||
|
||||
scalarTimer = new QTimer(this);
|
||||
connect( scalarTimer, &QTimer::timeout, scalarWorker, &ScalarWorker::UpdateScalar);
|
||||
// scalarTimer = new QTimer(this);
|
||||
// connect( scalarTimer, &QTimer::timeout, scalarWorker, &ScalarWorker::UpdateScalar);
|
||||
|
||||
scalarThread->start();
|
||||
// scalarThread->start();
|
||||
|
||||
unsigned short maxNChannel = 0;
|
||||
for( unsigned int k = 0; k < nDigi; k ++ ){
|
||||
|
@ -1068,8 +1076,8 @@ void FSUDAQ::UpdateScalar(){
|
|||
|
||||
lbTotalFileSize->setText("Total Data Size : " + QString::number(totalFileSize/1024./1024., 'f', 3) + " MB");
|
||||
|
||||
repaint();
|
||||
scalar->repaint();
|
||||
// repaint();
|
||||
// scalar->repaint();
|
||||
|
||||
if( influx && chkInflux->isChecked() && scalarCount >= 3){
|
||||
if( chkSaveData->isChecked() ) {
|
||||
|
@ -1081,6 +1089,8 @@ void FSUDAQ::UpdateScalar(){
|
|||
influx->ClearDataPointsBuffer();
|
||||
scalarCount = 0;
|
||||
}
|
||||
|
||||
// printf("end of %s\n", __func__);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1162,7 +1172,8 @@ void FSUDAQ::StartACQ(){
|
|||
// printf("------------ Go! \n");
|
||||
// for( unsigned int i = 0; i < nDigi; i++) readDataThread[i]->go();
|
||||
|
||||
if( scalar ) scalarTimer->start(ScalarUpdateinMiliSec);
|
||||
// if( scalar ) scalarTimer->start(ScalarUpdateinMiliSec);
|
||||
if( scalar ) scalarTimingThread->start();
|
||||
|
||||
if( !scalar->isVisible() ) {
|
||||
scalar->show();
|
||||
|
@ -1239,7 +1250,13 @@ void FSUDAQ::StopACQ(){
|
|||
QCoreApplication::processEvents();
|
||||
}
|
||||
|
||||
if( scalar ) scalarTimer->stop();
|
||||
if( scalarTimingThread->isRunning()){
|
||||
scalarTimingThread->Stop();
|
||||
scalarTimingThread->quit();
|
||||
scalarTimingThread->wait();
|
||||
}
|
||||
|
||||
// if( scalar ) scalarTimer->stop();
|
||||
if( singleHistograms ) singleHistograms->stopTimer();
|
||||
if( onlineAnalyzer ) onlineAnalyzer->stopTimer();
|
||||
|
||||
|
@ -1731,7 +1748,8 @@ void FSUDAQ::OpenScope(){
|
|||
|
||||
if( scalar ){
|
||||
lbScalarACQStatus->setText("<font style=\"color: green;\"><b>ACQ On</b></font>");
|
||||
scalarTimer->start(ScalarUpdateinMiliSec);
|
||||
// scalarTimer->start(ScalarUpdateinMiliSec);
|
||||
scalarTimingThread->start();
|
||||
}
|
||||
|
||||
if( singleHistograms ) singleHistograms->startTimer();
|
||||
|
@ -1742,7 +1760,10 @@ void FSUDAQ::OpenScope(){
|
|||
|
||||
if( scalar ){
|
||||
lbScalarACQStatus->setText("<font style=\"color: red;\"><b>ACQ Off</b></font>");
|
||||
scalarTimer->stop();
|
||||
// scalarTimer->stop();
|
||||
scalarTimingThread->Stop();
|
||||
scalarTimingThread->quit();
|
||||
scalarTimingThread->wait();
|
||||
}
|
||||
|
||||
if( singleHistograms ) singleHistograms->stopTimer();
|
||||
|
|
36
FSUDAQ.h
36
FSUDAQ.h
|
@ -173,9 +173,11 @@ private:
|
|||
//@----- Scalar
|
||||
QMainWindow * scalar;
|
||||
QGridLayout * scalarLayout;
|
||||
QThread * scalarThread;
|
||||
ScalarWorker * scalarWorker;
|
||||
QTimer * scalarTimer;
|
||||
TimingThread * scalarTimingThread;
|
||||
// QThread * scalarThread;
|
||||
// ScalarWorker * scalarWorker;
|
||||
// QTimer * scalarTimer;
|
||||
|
||||
|
||||
// TimingThread * scalarThread;
|
||||
QLineEdit *** leTrigger; // need to delete manually
|
||||
|
@ -212,23 +214,23 @@ private:
|
|||
|
||||
//^======================== Scalar Worker
|
||||
|
||||
class ScalarWorker : public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScalarWorker(FSUDAQ * parent): SS(parent){}
|
||||
// class ScalarWorker : public QObject{
|
||||
// Q_OBJECT
|
||||
// public:
|
||||
// ScalarWorker(FSUDAQ * parent): SS(parent){}
|
||||
|
||||
public slots:
|
||||
void UpdateScalar(){
|
||||
SS->UpdateScalar();
|
||||
emit workDone();
|
||||
}
|
||||
// public slots:
|
||||
// void UpdateScalar(){
|
||||
// SS->UpdateScalar();
|
||||
// emit workDone();
|
||||
// }
|
||||
|
||||
signals:
|
||||
void workDone();
|
||||
// signals:
|
||||
// void workDone();
|
||||
|
||||
private:
|
||||
FSUDAQ * SS;
|
||||
};
|
||||
// private:
|
||||
// FSUDAQ * SS;
|
||||
// };
|
||||
|
||||
|
||||
#endif // MAINWINDOW_H
|
Loading…
Reference in New Issue
Block a user