mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 13:27:14 +02:00
adding a semaphore to handle end of acq
This commit is contained in:
@ -293,6 +293,9 @@ class Listener : private virtual slsReceiverDefs, public ThreadObject {
|
|||||||
/** if the udp socket is connected */
|
/** if the udp socket is connected */
|
||||||
bool udpSocketAlive;
|
bool udpSocketAlive;
|
||||||
|
|
||||||
|
/** Semaphore to synchonize deleting udp socket */
|
||||||
|
sem_t semaphore_socket;
|
||||||
|
|
||||||
|
|
||||||
// for print progress during acqusition
|
// for print progress during acqusition
|
||||||
/** number of packets for statistic */
|
/** number of packets for statistic */
|
||||||
|
@ -60,12 +60,13 @@ Listener::Listener(detectorType dtype, Fifo*& f, runStatus* s, uint32_t* portno,
|
|||||||
}
|
}
|
||||||
NumberofListeners++;
|
NumberofListeners++;
|
||||||
FILE_LOG(logDEBUG) << "Number of Listeners: " << NumberofListeners;
|
FILE_LOG(logDEBUG) << "Number of Listeners: " << NumberofListeners;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Listener::~Listener() {
|
Listener::~Listener() {
|
||||||
if (udpSocket) delete udpSocket;
|
if (udpSocket) delete udpSocket;
|
||||||
|
sem_post(&semaphore_socket);
|
||||||
|
sem_destroy(&semaphore_socket);
|
||||||
if (carryOverPacket) delete [] carryOverPacket;
|
if (carryOverPacket) delete [] carryOverPacket;
|
||||||
if (listeningPacket) delete [] listeningPacket;
|
if (listeningPacket) delete [] listeningPacket;
|
||||||
ThreadObject::DestroyThread();
|
ThreadObject::DestroyThread();
|
||||||
@ -230,6 +231,7 @@ int Listener::CreateUDPSockets() {
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
udpSocketAlive = true;
|
udpSocketAlive = true;
|
||||||
|
sem_init(&semaphore_socket,1,0);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,6 +244,10 @@ void Listener::ShutDownUDPSocket() {
|
|||||||
FILE_LOG(logINFO) << "Shut down of UDP port " << *udpPortNumber;
|
FILE_LOG(logINFO) << "Shut down of UDP port " << *udpPortNumber;
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
//delete socket at stoplistening
|
//delete socket at stoplistening
|
||||||
|
sem_wait(&semaphore_socket);
|
||||||
|
delete udpSocket;
|
||||||
|
udpSocket = 0;
|
||||||
|
sem_destroy(&semaphore_socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,10 +317,8 @@ void Listener::StopListening(char* buf) {
|
|||||||
(*((uint32_t*)buf)) = DUMMY_PACKET_VALUE;
|
(*((uint32_t*)buf)) = DUMMY_PACKET_VALUE;
|
||||||
fifo->PushAddress(buf);
|
fifo->PushAddress(buf);
|
||||||
StopRunning();
|
StopRunning();
|
||||||
if (udpSocket) {
|
|
||||||
delete udpSocket;
|
sem_post(&semaphore_socket);
|
||||||
udpSocket = 0;
|
|
||||||
}
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
cprintf(GREEN,"%d: Listening Packets (%u) : %llu\n", index, *udpPortNumber, numPacketsCaught);
|
cprintf(GREEN,"%d: Listening Packets (%u) : %llu\n", index, *udpPortNumber, numPacketsCaught);
|
||||||
cprintf(GREEN,"%d: Listening Completed\n", index);
|
cprintf(GREEN,"%d: Listening Completed\n", index);
|
||||||
|
Reference in New Issue
Block a user