ensure gui gets measurement finished after dummy packet received from receiver/ext process

This commit is contained in:
Dhanya Maliakal 2017-11-29 15:22:10 +01:00
parent 397344a264
commit 1edb41242c
3 changed files with 18 additions and 2 deletions

View File

@ -5942,12 +5942,16 @@ void multiSlsDetector::readFrameFromReceiver(){
//all done //all done
if(!numRunning){ if(!numRunning){
// let main thread know that all dummy packets have been received (also from external process),
// main thread can now proceed to measurement finished call back
sem_post(&sem_endRTAcquisition);
// wait for next scan/measurement, else join thread
sem_wait(&sem_newRTAcquisition); sem_wait(&sem_newRTAcquisition);
//done with complete acquisition //done with complete acquisition
if(checkJoinThread()) if(checkJoinThread())
break; break;
else{ else{
//starting a new scan/measurement //starting a new scan/measurement (got dummy data)
for(int i = 0; i < numSockets; ++i) for(int i = 0; i < numSockets; ++i)
runningList[i] = true; runningList[i] = true;
numRunning = numSockets; numRunning = numSockets;

View File

@ -58,6 +58,8 @@ int slsDetectorUtils::acquire(int delflag){
//not in the loop for real time acqusition yet, //not in the loop for real time acqusition yet,
//in the real time acquisition loop, processing thread will wait for a post each time //in the real time acquisition loop, processing thread will wait for a post each time
sem_init(&sem_newRTAcquisition,1,0); sem_init(&sem_newRTAcquisition,1,0);
//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); bool receiver = (setReceiverOnline()==ONLINE_FLAG);
@ -351,6 +353,11 @@ int slsDetectorUtils::acquire(int delflag){
else{ else{
if (stopReceiver() == FAIL) if (stopReceiver() == FAIL)
*stoppedFlag = 1; *stoppedFlag = 1;
else {
if (*threadedProcessing && dataReady) // threaded processing
sem_wait(&sem_endRTAcquisition); // waits for receiver's external process to be done sending data to gui
}
// cout<<"***********receiver stopped"<<endl; // cout<<"***********receiver stopped"<<endl;
} }
pthread_mutex_unlock(&mg);//cout << "unlock"<< endl; pthread_mutex_unlock(&mg);//cout << "unlock"<< endl;
@ -504,13 +511,15 @@ int slsDetectorUtils::acquire(int delflag){
cout << "acquisition finished callback done " << endl; cout << "acquisition finished callback done " << endl;
#endif #endif
setAcquiringFlag(false);
sem_destroy(&sem_newRTAcquisition); sem_destroy(&sem_newRTAcquisition);
sem_destroy(&sem_endRTAcquisition);
#ifdef VERBOSE #ifdef VERBOSE
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl; cout << "Elapsed time for acquisition:" << (( end.tv_sec - begin.tv_sec ) + ( end.tv_nsec - begin.tv_nsec ) / 1000000000.0) << " seconds" << endl;
#endif #endif
setAcquiringFlag(false);
return OK; return OK;
} }

View File

@ -1000,7 +1000,10 @@ virtual int setReceiverSilentMode(int i = -1)=0;
int (*progress_call)(double,void*); int (*progress_call)(double,void*);
void *pProgressCallArg; void *pProgressCallArg;
/** semaphore to let postprocessing thread continue for next scan/measurement */
sem_t sem_newRTAcquisition; sem_t sem_newRTAcquisition;
/** semaphore to let main thread know it got all the dummy packets (also from ext. process) */
sem_t sem_endRTAcquisition;
}; };