Merge branch 'arping' into eiger_datastream

This commit is contained in:
maliakal_d 2022-02-04 10:41:58 +01:00
commit 8f2bacfd53
10 changed files with 23 additions and 39 deletions

View File

@ -4,7 +4,6 @@
#include "Arping.h" #include "Arping.h"
#include <chrono> #include <chrono>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
void Arping::SetInterfacesAndIps(const int index, const std::string &interface, void Arping::SetInterfacesAndIps(const int index, const std::string &interface,
@ -44,7 +43,7 @@ void Arping::StopThread() {
} }
void Arping::ThreadExecution() { void Arping::ThreadExecution() {
threadId = syscall(SYS_gettid); threadId = gettid();
LOG(logINFOBLUE) << "Created [ Arping Thread, Tid: " << threadId << " ]"; LOG(logINFOBLUE) << "Created [ Arping Thread, Tid: " << threadId << " ]";
while (runningFlag) { while (runningFlag) {

View File

@ -12,7 +12,7 @@ is listening to.
#include <atomic> #include <atomic>
#include <thread> #include <thread>
class Arping : private virtual slsDetectorDefs { class Arping {
public: public:
void SetInterfacesAndIps(const int index, const std::string &interface, void SetInterfacesAndIps(const int index, const std::string &interface,
@ -31,5 +31,5 @@ class Arping : private virtual slsDetectorDefs {
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS); std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
std::atomic<bool> runningFlag{false}; std::atomic<bool> runningFlag{false};
std::thread t; std::thread t;
pid_t threadId{0}; std::atomic<pid_t> threadId{0};
}; };

View File

@ -19,7 +19,6 @@
#include <memory> #include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
#include <vector> #include <vector>
@ -41,7 +40,7 @@ ClientInterface::ClientInterface(int portNumber)
portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2), portNumber(portNumber > 0 ? portNumber : DEFAULT_PORTNO + 2),
server(portNumber) { server(portNumber) {
functionTable(); functionTable();
parentThreadId = syscall(SYS_gettid); parentThreadId = gettid();
tcpThread = tcpThread =
sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this); sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this);
} }
@ -76,7 +75,7 @@ void ClientInterface::registerCallBackRawDataModifyReady(
} }
void ClientInterface::startTCPServer() { void ClientInterface::startTCPServer() {
tcpThreadId = syscall(SYS_gettid); tcpThreadId = gettid();
LOG(logINFOBLUE) << "Created [ TCP server Tid: " << tcpThreadId << "]"; LOG(logINFOBLUE) << "Created [ TCP server Tid: " << tcpThreadId << "]";
LOG(logINFO) << "SLS Receiver starting TCP Server on port " << portNumber LOG(logINFO) << "SLS Receiver starting TCP Server on port " << portNumber
<< '\n'; << '\n';

View File

@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-3.0-or-other // SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package // Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Implementation.h" #include "Implementation.h"
#include "Arping.h"
#include "DataProcessor.h" #include "DataProcessor.h"
#include "DataStreamer.h" #include "DataStreamer.h"
#include "Fifo.h" #include "Fifo.h"
@ -109,9 +108,6 @@ void Implementation::SetupFifoStructure() {
void Implementation::setDetectorType(const detectorType d) { void Implementation::setDetectorType(const detectorType d) {
// object to create thread for arping
arping = sls::make_unique<Arping>();
detType = d; detType = d;
switch (detType) { switch (detType) {
case GOTTHARD: case GOTTHARD:
@ -325,21 +321,19 @@ std::array<pid_t, NUM_RX_THREAD_IDS> Implementation::getThreadIds() const {
retval[id++] = 0; retval[id++] = 0;
} }
} }
retval[NUM_RX_THREAD_IDS - 1] = arping->GetThreadId(); retval[NUM_RX_THREAD_IDS - 1] = arping.GetThreadId();
return retval; return retval;
} }
bool Implementation::getArping() const { return arping->IsRunning(); } bool Implementation::getArping() const { return arping.IsRunning(); }
pid_t Implementation::getArpingThreadId() const { pid_t Implementation::getArpingThreadId() const { return arping.GetThreadId(); }
return arping->GetThreadId();
}
void Implementation::setArping(const bool i, void Implementation::setArping(const bool i,
const std::vector<std::string> ips) { const std::vector<std::string> ips) {
if (i != arping->IsRunning()) { if (i != arping.IsRunning()) {
if (!i) { if (!i) {
arping->StopThread(); arping.StopThread();
} else { } else {
// setup interface // setup interface
for (int i = 0; i != numUDPInterfaces; ++i) { for (int i = 0; i != numUDPInterfaces; ++i) {
@ -347,9 +341,9 @@ void Implementation::setArping(const bool i,
if (i == 1 && (numUDPInterfaces == 1 || detType == EIGER)) { if (i == 1 && (numUDPInterfaces == 1 || detType == EIGER)) {
break; break;
} }
arping->SetInterfacesAndIps(i, eth[i], ips[i]); arping.SetInterfacesAndIps(i, eth[i], ips[i]);
} }
arping->StartThread(); arping.StartThread();
} }
} }
} }

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-other // SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package // Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once #pragma once
#include "Arping.h"
#include "receiver_defs.h" #include "receiver_defs.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include "sls/logger.h" #include "sls/logger.h"
@ -11,7 +12,6 @@ class DataProcessor;
class DataStreamer; class DataStreamer;
class Fifo; class Fifo;
class slsDetectorDefs; class slsDetectorDefs;
class Arping;
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>
@ -383,7 +383,7 @@ class Implementation : private virtual slsDetectorDefs {
std::vector<std::unique_ptr<DataProcessor>> dataProcessor; std::vector<std::unique_ptr<DataProcessor>> dataProcessor;
std::vector<std::unique_ptr<DataStreamer>> dataStreamer; std::vector<std::unique_ptr<DataStreamer>> dataStreamer;
std::vector<std::unique_ptr<Fifo>> fifo; std::vector<std::unique_ptr<Fifo>> fifo;
std::unique_ptr<Arping> arping; Arping arping;
std::mutex hdf5Lib; std::mutex hdf5Lib;
}; };

View File

@ -11,7 +11,6 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <semaphore.h> #include <semaphore.h>
#include <sys/syscall.h>
#include <sys/wait.h> //wait #include <sys/wait.h> //wait
#include <unistd.h> #include <unistd.h>
@ -172,8 +171,7 @@ int main(int argc, char *argv[]) {
(!sscanf(argv[3], "%d", &withCallback)))) (!sscanf(argv[3], "%d", &withCallback))))
printHelp(); printHelp();
cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", cprintf(BLUE, "Parent Process Created [ Tid: %ld ]\n", (long)gettid());
(long)syscall(SYS_gettid));
cprintf(RESET, "Number of Receivers: %d\n", numReceivers); cprintf(RESET, "Number of Receivers: %d\n", numReceivers);
cprintf(RESET, "Start TCP Port: %d\n", startTCPPort); cprintf(RESET, "Start TCP Port: %d\n", startTCPPort);
cprintf(RESET, "Callback Enable: %d\n", withCallback); cprintf(RESET, "Callback Enable: %d\n", withCallback);
@ -215,16 +213,14 @@ int main(int argc, char *argv[]) {
/** - if child process */ /** - if child process */
else if (pid == 0) { else if (pid == 0) {
cprintf(BLUE, "Child process %d [ Tid: %ld ]\n", i, cprintf(BLUE, "Child process %d [ Tid: %ld ]\n", i, (long)gettid());
(long)syscall(SYS_gettid));
std::unique_ptr<sls::Receiver> receiver = nullptr; std::unique_ptr<sls::Receiver> receiver = nullptr;
try { try {
receiver = sls::make_unique<sls::Receiver>(startTCPPort + i); receiver = sls::make_unique<sls::Receiver>(startTCPPort + i);
} catch (...) { } catch (...) {
LOG(logINFOBLUE) LOG(logINFOBLUE)
<< "Exiting Child Process [ Tid: " << syscall(SYS_gettid) << "Exiting Child Process [ Tid: " << gettid() << " ]";
<< " ]";
throw; throw;
} }
/** - register callbacks. remember to set file write enable to 0 /** - register callbacks. remember to set file write enable to 0
@ -254,7 +250,7 @@ int main(int argc, char *argv[]) {
sem_wait(&semaphore); sem_wait(&semaphore);
sem_destroy(&semaphore); sem_destroy(&semaphore);
cprintf(BLUE, "Exiting Child Process [ Tid: %ld ]\n", cprintf(BLUE, "Exiting Child Process [ Tid: %ld ]\n",
(long)syscall(SYS_gettid)); (long)gettid());
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
} }

View File

@ -14,7 +14,6 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
namespace sls { namespace sls {
@ -68,8 +67,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
case 'v': case 'v':
std::cout << "SLS Receiver Version: " << GITBRANCH << " (0x" std::cout << "SLS Receiver Version: " << GITBRANCH << " (0x"
<< std::hex << APIRECEIVER << ")" << std::endl; << std::hex << APIRECEIVER << ")" << std::endl;
LOG(logINFOBLUE) LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
<< "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h': case 'h':

View File

@ -8,7 +8,6 @@
#include <csignal> //SIGINT #include <csignal> //SIGINT
#include <semaphore.h> #include <semaphore.h>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
sem_t semaphore; sem_t semaphore;
@ -19,7 +18,7 @@ int main(int argc, char *argv[]) {
sem_init(&semaphore, 1, 0); sem_init(&semaphore, 1, 0);
LOG(logINFOBLUE) << "Created [ Tid: " << syscall(SYS_gettid) << " ]"; LOG(logINFOBLUE) << "Created [ Tid: " << gettid() << " ]";
// Catch signal SIGINT to close files and call destructors properly // Catch signal SIGINT to close files and call destructors properly
struct sigaction sa; struct sigaction sa;
@ -50,7 +49,7 @@ int main(int argc, char *argv[]) {
} catch (...) { } catch (...) {
// pass // pass
} }
LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]"; LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
LOG(logINFO) << "Exiting Receiver"; LOG(logINFO) << "Exiting Receiver";
return 0; return 0;
} }

View File

@ -8,7 +8,6 @@
#include "ThreadObject.h" #include "ThreadObject.h"
#include "sls/container_utils.h" #include "sls/container_utils.h"
#include <iostream> #include <iostream>
#include <sys/syscall.h>
#include <unistd.h> #include <unistd.h>
ThreadObject::ThreadObject(int threadIndex, std::string threadType) ThreadObject::ThreadObject(int threadIndex, std::string threadType)
@ -39,7 +38,7 @@ void ThreadObject::StartRunning() { runningFlag = true; }
void ThreadObject::StopRunning() { runningFlag = false; } void ThreadObject::StopRunning() { runningFlag = false; }
void ThreadObject::RunningThread() { void ThreadObject::RunningThread() {
threadId = syscall(SYS_gettid); threadId = gettid();
LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index LOG(logINFOBLUE) << "Created [ " << type << "Thread " << index
<< ", Tid: " << threadId << "]"; << ", Tid: " << threadId << "]";
while (!killThread) { while (!killThread) {

View File

@ -45,5 +45,5 @@ class ThreadObject : private virtual slsDetectorDefs {
std::thread threadObject; std::thread threadObject;
sem_t semaphore; sem_t semaphore;
const std::string type; const std::string type;
pid_t threadId{0}; std::atomic<pid_t> threadId{0};
}; };