mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 16:20:03 +02:00
rxr: semaphore instead of keeprunning variable at startup
This commit is contained in:
parent
e527aad6ab
commit
53e5a097ab
@ -14,11 +14,12 @@
|
||||
#include <syscall.h>
|
||||
#include <unistd.h> //usleep
|
||||
#include <memory>
|
||||
#include <semaphore.h>
|
||||
|
||||
bool keeprunning;
|
||||
sem_t semaphore;
|
||||
|
||||
void sigInterruptHandler(int p){
|
||||
keeprunning = false;
|
||||
sem_post(&semaphore);
|
||||
}
|
||||
|
||||
/** Define Colors to print data call back in different colors for different recievers */
|
||||
@ -65,7 +66,8 @@ void GetData(char* metadata, char* datapointer, uint32_t datasize, void* p){
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
keeprunning = true;
|
||||
sem_init(&semaphore,1,0);
|
||||
|
||||
FILE_LOG(logINFOBLUE) << "Created [ Tid: " << syscall(SYS_gettid) << " ]";
|
||||
|
||||
// Catch signal SIGINT to close files and call destructors properly
|
||||
@ -136,8 +138,8 @@ int main(int argc, char *argv[]) {
|
||||
//receiver->registerCallBackRawDataReady(rawDataReadyCallBack,NULL);
|
||||
|
||||
FILE_LOG(logINFO) << "[ Press \'Ctrl+c\' to exit ]";
|
||||
while(keeprunning)
|
||||
pause();
|
||||
sem_wait(&semaphore);
|
||||
sem_destroy(&semaphore);
|
||||
FILE_LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
|
||||
FILE_LOG(logINFO) << "Exiting Receiver";
|
||||
return 0;
|
||||
|
@ -29,6 +29,7 @@ It is linked in manual/manual-api from slsReceiverSoftware/include ]
|
||||
#include <sys/wait.h> //wait
|
||||
#include <syscall.h> //tid
|
||||
#include <unistd.h> //usleep
|
||||
#include <semaphore.h>
|
||||
using namespace std;
|
||||
|
||||
|
||||
@ -36,15 +37,14 @@ using namespace std;
|
||||
#define PRINT_IN_COLOR(c,f, ...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
|
||||
|
||||
|
||||
/** Variable is true to continue running, set to false upon interrupt */
|
||||
bool keeprunning;
|
||||
sem_t semaphore;
|
||||
|
||||
/**
|
||||
* Control+C Interrupt Handler
|
||||
* Sets the variable keeprunning to false, to let all the processes know to exit properly
|
||||
* to let all the processes know to exit properly
|
||||
*/
|
||||
void sigInterruptHandler(int p){
|
||||
keeprunning = false;
|
||||
sem_post(&semaphore);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,7 +165,7 @@ int main(int argc, char *argv[]) {
|
||||
int numReceivers = 1;
|
||||
int startTCPPort = 1954;
|
||||
int withCallback = 0;
|
||||
keeprunning = true;
|
||||
sem_init(&semaphore,1,0);
|
||||
|
||||
/** - get number of receivers and start tcp port from command line arguments */
|
||||
if ( (argc != 4) || (!sscanf(argv[1],"%d", &startTCPPort)) || (!sscanf(argv[2],"%d", &numReceivers)) || (!sscanf(argv[3],"%d", &withCallback)) )
|
||||
@ -238,9 +238,9 @@ int main(int argc, char *argv[]) {
|
||||
else if (withCallback == 2) receiver->registerCallBackRawDataModifyReady(GetData,nullptr);
|
||||
}
|
||||
|
||||
/** - as long as keeprunning is true (changes with Ctrl+C) */
|
||||
while(keeprunning)
|
||||
pause();
|
||||
/** - as long as no Ctrl+C */
|
||||
sem_wait(&semaphore);
|
||||
sem_destroy(&semaphore);
|
||||
cprintf(BLUE,"Exiting Child Process [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user