From 0070a79838ac278ec11a4d83c673e99686a3435b Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 17 Oct 2018 17:35:55 +0200 Subject: [PATCH] removed command threaded --- CMakeLists.txt | 4 +- .../multiSlsDetector/multiSlsDetector.cpp | 51 +++--------------- .../multiSlsDetector/multiSlsDetector.h | 9 +--- .../slsDetector/slsDetector.cpp | 2 +- slsDetectorSoftware/slsDetector/slsDetector.h | 2 +- .../slsDetector/slsDetectorCommand.cpp | 54 +++++++++---------- .../slsDetector/slsDetectorCommand.h | 2 +- 7 files changed, 40 insertions(+), 84 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 056a65561..7373a7ea2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,8 @@ else () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11") endif () -set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") -set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") +set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") +set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread") find_package(Qt4) find_package(Qwt 6) diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index 69e10c3c7..ff4bd6df6 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -406,7 +406,7 @@ void multiSlsDetector::initializeDetectorStructure() { for (int i = 0; i < MAX_TIMERS; ++i) { thisMultiDetector->timerValue[i] = 0; } - thisMultiDetector->threadedProcessing = 1; + thisMultiDetector->acquiringFlag = false; thisMultiDetector->receiverOnlineFlag = OFFLINE_FLAG; thisMultiDetector->receiver_upstream = false; @@ -3661,7 +3661,6 @@ void multiSlsDetector::setCurrentProgress(int i){ int multiSlsDetector::acquire(){ - //ensure acquire isnt started multiple times by same client if (isAcquireReady() == FAIL) return FAIL; @@ -3676,12 +3675,9 @@ int multiSlsDetector::acquire(){ //in the real time acquistion loop, main thread will wait for processing thread to be done each time (which in turn waits for receiver/ext process) sem_init(&sem_endRTAcquisition,1,0); - bool receiver = (setReceiverOnline()==ONLINE_FLAG); - progressIndex=0; thisMultiDetector->stoppedFlag=0; - void *status; setJoinThread(0); int nm=thisMultiDetector->timerValue[MEASUREMENTS_NUMBER]; @@ -3696,9 +3692,7 @@ int multiSlsDetector::acquire(){ thisMultiDetector->stoppedFlag=1; } - // start processing thread - if (thisMultiDetector->threadedProcessing) - startProcessingThread(); + startProcessingThread(); //resets frames caught in receiver if(receiver){ @@ -3725,20 +3719,15 @@ int multiSlsDetector::acquire(){ sem_post(&sem_newRTAcquisition); } - // detector start startAndReadAll(); - if (thisMultiDetector->threadedProcessing==0){ - processData(); - } - // stop receiver std::lock_guard lock(mg); if(receiver){ if (stopReceiver() == FAIL) { thisMultiDetector->stoppedFlag = 1; } else { - if (thisMultiDetector->threadedProcessing && dataReady) + if (dataReady) sem_wait(&sem_endRTAcquisition); // waits for receiver's external process to be done sending data to gui } } @@ -3754,17 +3743,10 @@ int multiSlsDetector::acquire(){ }//end measurements loop im - // waiting for the data processing thread to finish! - if (thisMultiDetector->threadedProcessing) { - setJoinThread(1); - - //let processing thread continue and checkjointhread - sem_post(&sem_newRTAcquisition); - - // pthread_join(dataProcessingThread, &status); - dataProcessingThread.join(); - } + setJoinThread(1); + sem_post(&sem_newRTAcquisition); + dataProcessingThread.join(); if(progress_call) @@ -3790,13 +3772,6 @@ int multiSlsDetector::acquire(){ -int multiSlsDetector::setThreadedProcessing(int enable) { - if (enable>=0) - thisMultiDetector->threadedProcessing=enable; - return thisMultiDetector->threadedProcessing; -} - - void multiSlsDetector::startProcessingThread() { setTotalProgress(); dataProcessingThread = std::thread(&multiSlsDetector::processData, this); @@ -3821,35 +3796,23 @@ void multiSlsDetector::processData() { else{ int caught = -1; while(true){ - - // set only in startThread - if (thisMultiDetector->threadedProcessing==0) - setTotalProgress(); - // to exit acquire by typing q if (kbhit()!=0){ - char c = fgetc(stdin); - if (c=='q') { + if (fgetc(stdin) == 'q') { std::cout<<"Caught the command to stop acquisition"< lock(mg); caught = getFramesCaughtByReceiver(0); } - //updating progress if(caught!= -1){ setCurrentProgress(caught); } - // exiting loop - if (thisMultiDetector->threadedProcessing==0) - break; if (checkJoinThread()){ break; } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 1c2bcffd0..daaedc3e5 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -102,9 +102,6 @@ private: /** timer values */ int64_t timerValue[MAX_TIMERS]; - /** threaded processing flag (i.e. if data are processed and written to - * file in a separate thread) */ - int threadedProcessing; /** flag for acquiring */ bool acquiringFlag; @@ -1573,11 +1570,7 @@ public: */ int acquire(); - /** - * Set/get if the data processing thread si enabled - * @param enable 0 no data processing thread, 1 separate thread, -1 get - */ - int setThreadedProcessing(int enable=-1); + /** * Returns true if detector position is out of bounds diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 07a994a58..942dd67de 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -439,7 +439,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) { thisDetector->nTrimEn = 0; for(int i = 0; i < MAX_TRIMEN; ++i) thisDetector->trimEnergies[i] = 0; - thisDetector->threadedProcessing = 1; + // thisDetector->threadedProcessing = 1; thisDetector->nROI = 0; memset(thisDetector->roiLimits, 0, MAX_ROIS * sizeof(ROI)); thisDetector->roFlags = NORMAL_READOUT; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 13f7ef752..1c783fdf8 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -126,7 +126,7 @@ private: /** threaded processing flag * (i.e. if data are processed in a separate thread) */ - int threadedProcessing; + // int threadedProcessing; /** number of rois defined */ int nROI; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index ffc9de7a3..2e94bd16b 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -812,12 +812,12 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdRateCorr; ++i; - /*! \page data - - threaded [i] Sets/gets the data processing threaded flag. 1 is threaded, 0 unthreaded. - */ - descrToFuncMap[i].m_pFuncName="threaded"; // - descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded; - ++i; +// /*! \page data +// - threaded [i] Sets/gets the data processing threaded flag. 1 is threaded, 0 unthreaded. +// */ +// descrToFuncMap[i].m_pFuncName="threaded"; // +// descrToFuncMap[i].m_pFuncPtr=&slsDetectorCommand::cmdThreaded; +// ++i; /*! \page data - darkimage fn Loads the dark image to the detector from file fn (pedestal image). Cannot get. For Gotthard only. @@ -2161,15 +2161,15 @@ string slsDetectorCommand::cmdData(int narg, char *args[], int action, int detPo } else if (action==HELP_ACTION) { return helpData(HELP_ACTION); } else { - b=myDet->setThreadedProcessing(-1); - myDet->setThreadedProcessing(0); - myDet->setOnline(ONLINE_FLAG, detPos); - myDet->setReceiverOnline(ONLINE_FLAG, detPos); - myDet->readAll(detPos); - //processdata in receiver is useful only for gui purposes - if(myDet->setReceiverOnline(detPos)==OFFLINE_FLAG) - myDet->processData(); - myDet->setThreadedProcessing(b); + // b=myDet->setThreadedProcessing(-1); + // myDet->setThreadedProcessing(0); + // myDet->setOnline(ONLINE_FLAG, detPos); + // myDet->setReceiverOnline(ONLINE_FLAG, detPos); + // myDet->readAll(detPos); + // //processdata in receiver is useful only for gui purposes + // if(myDet->setReceiverOnline(detPos)==OFFLINE_FLAG) + // myDet->processData(); + // myDet->setThreadedProcessing(b); return string(""); } } @@ -2744,21 +2744,21 @@ string slsDetectorCommand::helpRateCorr(int action){ -string slsDetectorCommand::cmdThreaded(int narg, char *args[], int action, int detPos){ - int ival; - char answer[1000]; +// string slsDetectorCommand::cmdThreaded(int narg, char *args[], int action, int detPos){ +// int ival; +// char answer[1000]; - if (action==HELP_ACTION) - return helpThreaded(action); +// if (action==HELP_ACTION) +// return helpThreaded(action); - if (action==PUT_ACTION) { - if (sscanf(args[1],"%d",&ival)) - myDet->setThreadedProcessing(ival); - } - sprintf(answer,"%d",myDet->setThreadedProcessing()); - return string(answer); +// if (action==PUT_ACTION) { +// if (sscanf(args[1],"%d",&ival)) +// myDet->setThreadedProcessing(ival); +// } +// sprintf(answer,"%d",myDet->setThreadedProcessing()); +// return string(answer); -} +// } string slsDetectorCommand::helpThreaded(int action){ diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h index ce7ca999d..d5afb3fc0 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.h +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.h @@ -113,7 +113,7 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdFileName(int narg, char *args[], int action, int detPos = -1); std::string cmdFileIndex(int narg, char *args[], int action, int detPos = -1); std::string cmdRateCorr(int narg, char *args[], int action, int detPos = -1); - std::string cmdThreaded(int narg, char *args[], int action, int detPos = -1); + // std::string cmdThreaded(int narg, char *args[], int action, int detPos = -1); std::string cmdNetworkParameter(int narg, char *args[], int action, int detPos = -1); std::string cmdPort(int narg, char *args[], int action, int detPos = -1); std::string cmdLock(int narg, char *args[], int action, int detPos = -1);