minor changes, but posted semaphore in stop receiver so rxr not waiting forever for gui when it will never come

This commit is contained in:
Dhanya Maliakal
2015-06-12 17:46:50 +02:00
parent b27f691d03
commit bcf8d40fd2

View File

@ -890,7 +890,7 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui
if (guiData == NULL){ if (guiData == NULL){
guiData = latestData; guiData = latestData;
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "gui data not null anymore" << endl; cprintf(CYAN,"gui data not null anymore\n");
#endif #endif
} }
@ -904,14 +904,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui
//could not get gui data //could not get gui data
if(!guiDataReady){ if(!guiDataReady){
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "gui data not ready" << endl; cprintf(CYAN,"gui data not ready\n");
#endif #endif
*raw = NULL; *raw = NULL;
} }
//data ready, set guidata to receive new data //data ready, set guidata to receive new data
else{ else{
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "gui data ready" << endl; cprintf(CYAN,"gui data ready\n");
#endif #endif
*raw = guiData; *raw = guiData;
guiData = NULL; guiData = NULL;
@ -921,14 +921,14 @@ void UDPStandardImplementation::readFrame(char* c,char** raw, uint32_t &fnum, ui
pthread_mutex_unlock(&dataReadyMutex);*/ pthread_mutex_unlock(&dataReadyMutex);*/
if((nFrameToGui) && (writerthreads_mask)){ if((nFrameToGui) && (writerthreads_mask)){
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "gonna post" << endl; cprintf(CYAN,"gonna post\n");
#endif #endif
/*if(nFrameToGui){*/ /*if(nFrameToGui){*/
//release after getting data //release after getting data
sem_post(&smp); sem_post(&smp);
} }
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "done post" << endl; cprintf(CYAN,"done post\n");
#endif #endif
} }
} }
@ -947,7 +947,7 @@ cout << "copyframe" << endl;
//else guidata always null as guidataready is always 1 after 1st frame, and seccond data never gets copied //else guidata always null as guidataready is always 1 after 1st frame, and seccond data never gets copied
if((!nFrameToGui) && (!guiData)){ if((!nFrameToGui) && (!guiData)){
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "doing nothing" << endl; cprintf(GREEN,"doing nothing\n");
#endif #endif
pthread_mutex_lock(&dataReadyMutex); pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0; guiDataReady=0;
@ -957,12 +957,12 @@ cout << "copyframe" << endl;
//random read or nth frame read, gui needs data now or it is the first frame //random read or nth frame read, gui needs data now or it is the first frame
else{ else{
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "gui needs data now or 1st frame" << endl; cprintf(GREEN,"gui needs data now or 1st frame\n");
#endif #endif
pthread_mutex_lock(&dataReadyMutex); pthread_mutex_lock(&dataReadyMutex);
guiDataReady=0; guiDataReady=0;
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "guidataready is 0, copying data" << endl; cprintf(GREEN,"guidataready is 0, copying data\n");
#endif #endif
//eiger //eiger
if(startbuf != NULL){ if(startbuf != NULL){
@ -989,16 +989,16 @@ cout << "copyframe" << endl;
guiDataReady=1; guiDataReady=1;
pthread_mutex_unlock(&dataReadyMutex); pthread_mutex_unlock(&dataReadyMutex);
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout << "guidataready = 1" << endl; cprintf(GREEN,"guidataready = 1\n");
#endif #endif
//nth frame read, block current process if the guireader hasnt read it yet //nth frame read, block current process if the guireader hasnt read it yet
if(nFrameToGui){ if(nFrameToGui){
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout<<"waiting after copying"<<endl; cprintf(GREEN,"waiting after copying\n");
#endif #endif
sem_wait(&smp); sem_wait(&smp);
#ifdef VERY_VERY_DEBUG #ifdef VERY_VERY_DEBUG
cout<<"done waiting"<<endl; cprintf(GREEN,"done waiting\n");
#endif #endif
} }
@ -1571,11 +1571,12 @@ int UDPStandardImplementation::stopReceiver(){
startReadout(); startReadout();
while(status == TRANSMITTING) while(status == TRANSMITTING){
sem_post(&smp);
usleep(5000); usleep(5000);
}
//semaphore destroy //semaphore destroy
sem_post(&smp);
sem_destroy(&smp); sem_destroy(&smp);
//change status //change status
@ -1586,6 +1587,10 @@ int UDPStandardImplementation::stopReceiver(){
cout << "Receiver Stopped.\nStatus:" << status << endl << endl; cout << "Receiver Stopped.\nStatus:" << status << endl << endl;
}else cout <<" Not idle to stop receiver" << endl; }else cout <<" Not idle to stop receiver" << endl;
//sem_post(&smp);
return OK; return OK;
} }
@ -1833,7 +1838,7 @@ int UDPStandardImplementation::startListening(){
while(!fifo[ithread]->push(buffer[ithread])); while(!fifo[ithread]->push(buffer[ithread]));
#ifdef FIFO_DEBUG #ifdef FIFO_DEBUG
//if(!ithread) //if(!ithread)
cprintf(RED, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread])); cprintf(MAGENTA, "%d listener pushed into fifo %x\n",ithread, (void*)(buffer[ithread]));
#endif #endif
} }
@ -1934,7 +1939,7 @@ int UDPStandardImplementation::startWriting(){
continue; continue;
} }
#ifdef VERYDEBUG #ifdef VERYDEBUG
else cout <<"**NOT a dummy packet"<<endl; else cout <<"**NOT a dummy packet"<< dec << numpackets<< endl;
#endif #endif
@ -2025,18 +2030,18 @@ int UDPStandardImplementation::startWriting(){
writeToFile_withoutCompression(wbuf[j], numpackets,currframenum); writeToFile_withoutCompression(wbuf[j], numpackets,currframenum);
} }
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << "written everyting" << endl; cprintf(BLUE,"written everyting\n");
#endif #endif
} }
if(myDetectorType == EIGER) { if(myDetectorType == EIGER) {
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << "gonna copy frame" << endl; cprintf(BLUE,"gonna copy frame\n");
#endif #endif
copyFrameToGui(wbuf,currframenum); copyFrameToGui(wbuf,currframenum);
#ifdef VERYDEBUG #ifdef VERYDEBUG
cout << "copied frame" << endl; cprintf(BLUE,"copied frame\n");
#endif #endif
for(i=0;i<numListeningThreads;++i){ for(i=0;i<numListeningThreads;++i){
while(!fifoFree[i]->push(wbuf[i])); while(!fifoFree[i]->push(wbuf[i]));
@ -2196,7 +2201,7 @@ int i;
//free buffer //free buffer
if(rc <= 0){ if(rc <= 0){
cout << ithread << "Discarding empty frame/ End of acquisition" << endl; cout << ithread << "Discarding empty frame/ End of acquisition" << endl;
fifoFree[ithread]->push(buffer[ithread]); fifoFree[ithread]->push(buffer[ithread]);/** why not while(!)*/
#ifdef FIFO_DEBUG #ifdef FIFO_DEBUG
cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread])); cprintf(BLUE,"%d listener empty buffer pushed into fifofree %x\n", ithread, (void*)(buffer[ithread]));
#endif #endif
@ -2208,7 +2213,7 @@ int i;
if(rc == 266240) if(rc == 266240)
cprintf(GREEN, "%d Start of detector: Received test frame of 266240 bytes.\n",ithread); cprintf(GREEN, "%d Start of detector: Received test frame of 266240 bytes.\n",ithread);
cout << ithread << "Discarding incomplete frame" << endl; cout << ithread << "Discarding incomplete frame" << endl;
fifoFree[ithread]->push(buffer[ithread]); fifoFree[ithread]->push(buffer[ithread]);/** why not while(!)*/
#ifdef FIFO_DEBUG #ifdef FIFO_DEBUG
cprintf(BLUE,"%d listener last buffer free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread])); cprintf(BLUE,"%d listener last buffer free pushed into fifofree %x\n", ithread,(void*)(buffer[ithread]));
#endif #endif