diff --git a/slsReceiverSoftware/src/main.cpp b/slsReceiverSoftware/src/main.cpp index 6cb7b147e..ef99ab8a7 100755 --- a/slsReceiverSoftware/src/main.cpp +++ b/slsReceiverSoftware/src/main.cpp @@ -14,11 +14,12 @@ #include #include //usleep #include +#include -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; diff --git a/slsReceiverSoftware/src/multiReceiver.cpp b/slsReceiverSoftware/src/multiReceiver.cpp index ce9053113..87fd37b6e 100755 --- a/slsReceiverSoftware/src/multiReceiver.cpp +++ b/slsReceiverSoftware/src/multiReceiver.cpp @@ -29,6 +29,7 @@ It is linked in manual/manual-api from slsReceiverSoftware/include ] #include //wait #include //tid #include //usleep +#include 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;