diff --git a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp index d5c2c018a..f4d7e5d6d 100644 --- a/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp +++ b/slsDetectorSoftware/slsReceiver/slsReceiverFunctionList.cpp @@ -114,8 +114,8 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): receiverdata[i] = NULL; #ifdef MYROOT1 - myTree[i] = (NULL); - myFile[i] = (NULL); + myTree[i] = (NULL); + myFile[i] = (NULL); #endif } @@ -133,7 +133,6 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): cout << "\nWARNING: Could not change socket receiver buffer size in file /proc/sys/net/core/rmem_max" << endl; else if(system("echo 250000 > /proc/sys/net/core/netdev_max_backlog")) cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; - /** permanent setting heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 @@ -142,13 +141,24 @@ slsReceiverFunctionList::slsReceiverFunctionList(detectorType det): sysctl -w net.core.rmem_max=16777216 sysctl -w net.core.netdev_max_backlog=250000 */ -/* - if(createThreads() == FAIL){ + + + //threads + pthread_mutex_lock(&status_mutex); + status = IDLE; + pthread_mutex_unlock(&(status_mutex)); + + if(createListeningThreads() == FAIL){ + cout << "ERROR: Could not create listening thread" << endl; + exit (-1); + } + + if(createWriterThreads() == FAIL){ cout << "ERROR: Could not create writer threads" << endl; exit (-1); } -*/ + setThreadPriorities(); } @@ -161,7 +171,8 @@ slsReceiverFunctionList::~slsReceiverFunctionList(){ if(receiverdata[i]) delete receiverdata[i]; } - createThreads(true); + createListeningThreads(true); + createWriterThreads(true); if(udpSocket) delete udpSocket; if(eth) delete [] eth; @@ -308,21 +319,32 @@ int64_t slsReceiverFunctionList::setAcquisitionPeriod(int64_t index){ /******************* need to look at exit strategy **************************/ void slsReceiverFunctionList::enableDataCompression(bool enable){ + cout << "Data compression "; + if(enable) + cout << "enabled" << endl; + else + cout << "disabled" << endl; //delete filter for the current number of threads deleteFilter(); dataCompression = enable; pthread_mutex_lock(&status_mutex); - listening_thread_running = false; writerthreads_mask = 0x0; pthread_mutex_unlock(&(status_mutex)); - /*createThreads(true); need to make sure number of threads is correct when deleting old stuff*/ + createWriterThreads(true); + if(enable) numWriterThreads = MAX_NUM_WRITER_THREADS; else numWriterThreads = 1; - createThreads(); + + if(createWriterThreads() == FAIL){ + cout << "ERROR: Could not create writer threads" << endl; + exit (-1); + } + setThreadPriorities(); + if(enable) setupFilter(); @@ -506,8 +528,10 @@ void slsReceiverFunctionList::setupFifoStructure(){ //allocate memory mem0=(char*)malloc((bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*fifosize); /** shud let the client know about this */ - if (mem0==NULL) + if (mem0==NULL){ cout<<"++++++++++++++++++++++ COULD NOT ALLOCATE MEMORY FOR LISTENING !!!!!!!+++++++++++++++++++++" << endl; + exit(-1); + } buffer=mem0; //push the addresses into freed fifoFree and writingFifoFree while (buffer<(mem0+(bufferSize * numJobsPerThread + HEADER_SIZE_NUM_TOT_PACKETS)*(fifosize-1))) { @@ -558,33 +582,56 @@ int slsReceiverFunctionList::createUDPSocket(){ - -int slsReceiverFunctionList::createThreads(bool destroy){ - int i; +int slsReceiverFunctionList::createListeningThreads(bool destroy){ if(!destroy){ - pthread_mutex_lock(&status_mutex); - status = IDLE; listening_thread_running = 0; - writerthreads_mask = 0x0; pthread_mutex_unlock(&(status_mutex)); - //listening thread + cout << "Creating Listening Thread" << endl; sem_init(&listensmp,0,0); if(pthread_create(&listening_thread, NULL,startListeningThread, (void*) this)){ cout << "Could not create listening thread" << endl; return FAIL; } - //#ifdef VERBOSE +#ifdef VERBOSE cout << "Listening thread created successfully." << endl; - //#endif +#endif + }else{ + cout<<"Destroying Listening Thread"<