diff --git a/slsReceiverSoftware/src/ThreadArping.cpp b/slsReceiverSoftware/src/ThreadArping.cpp index 17e6d8824..674d12e4e 100644 --- a/slsReceiverSoftware/src/ThreadArping.cpp +++ b/slsReceiverSoftware/src/ThreadArping.cpp @@ -18,38 +18,24 @@ void ThreadArping::StartRunning() { if (arpInterfaceIp.size() == 0) { throw sls::RuntimeError("No Interface added to Arping"); } - threads.clear(); - threadIds.clear(); runningFlag = true; - // create threadss - for (auto arp : arpInterfaceIp) { - try { - std::thread temp = - std::thread(&ThreadArping::RunningThread, this, - threads.size(), arp.first, arp.second); - threads.push_back(temp.native_handle()); - temp.detach(); - } catch (...) { - StopRunning(); - throw sls::RuntimeError("Could not create arping thread [" + - arp.first + ", " + arp.second + "]"); - } + // create thread + try { + std::thread temp = std::thread(&ThreadArping::RunningThread, this); + threadObject = temp.native_handle(); + temp.detach(); + } catch (...) { + throw sls::RuntimeError("Could not create arping thread"); } } } void ThreadArping::StopRunning() { - int i = 0; - for (auto t : threads) { - pthread_cancel(t); - LOG(logINFOBLUE) << "Killing [ Arping Thread " << i << ": (" - << arpInterfaceIp[i].first << ", " - << arpInterfaceIp[i].second << ")]"; - ++i; - } - threads.clear(); - runningFlag = false; + pthread_cancel(threadObject); + LOG(logINFOBLUE) << "Killing [ Arping Thread, Tid: " << threadId << "]"; +} +runningFlag = false; } void ThreadArping::ClearIpsAndInterfaces() { arpInterfaceIp.clear(); } @@ -58,22 +44,17 @@ void ThreadArping::AddIpsAndInterfaces(std::string interface, std::string ip) { arpInterfaceIp.push_back(std::make_pair(interface, ip)); } -void ThreadArping::RunningThread(int index, std::string interface, - std::string ip) { - pid_t threadId = syscall(SYS_gettid); - LOG(logINFOBLUE) << "Created [ Arping Thread " << index << ": (" - << interface << ", " << ip << ") Tid: " << threadId << "]"; - { - std::lock_guard lock(&mutexIds); - threadIds.push_back(threadId); - } +void ThreadArping::RunningThread() { + + threadId = syscall(SYS_gettid); + LOG(logINFOBLUE) << "Created [ Arping Thread, Tid: " << threadId << "]"; while (IsRunning()) { - LOG(logINFOBLUE) << "Going to sleep apring id " << threadId; + LOG(logINFOBLUE) << "Going to sleep"; + // wait for 60s usleep(60 * 1000 * 1000); } - LOG(logINFOBLUE) << "Exiting [ Arping Thread " << index << ": (" - << interface << ", " << ip << ") Tid: " << threadId << "]"; + LOG(logINFOBLUE) << "Exiting [ Arping Thread, Tid: " << threadId << "]"; } \ No newline at end of file diff --git a/slsReceiverSoftware/src/ThreadArping.h b/slsReceiverSoftware/src/ThreadArping.h index 9441497c1..f9595a725 100644 --- a/slsReceiverSoftware/src/ThreadArping.h +++ b/slsReceiverSoftware/src/ThreadArping.h @@ -10,7 +10,6 @@ listening to. #include "sls/sls_detector_defs.h" #include -#include #include #include #include // pair, make_pair @@ -21,10 +20,9 @@ class ThreadArping : private virtual slsDetectorDefs { std::atomic killThread{false}; std::atomic runningFlag{false}; - std::vector threads; + pthread_t threadObject; std::vector> arpInterfaceIp; - std::vector threadIds; - std::mutex mutexIds; + pid_t threadIds; public: ThreadArping(); @@ -41,5 +39,5 @@ class ThreadArping : private virtual slsDetectorDefs { * RunningMask is satisfied Then it exits the thread on its own if * killThread is true */ - void RunningThread(int index, std::string interface, std::string ip); + void RunningThread(std::string interface, std::string ip); };