review, replacing syscall(sys_gettid) with gettid()

This commit is contained in:
2022-02-04 09:51:49 +01:00
parent 3350e3997e
commit e8cf366616
6 changed files with 11 additions and 21 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

@ -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

@ -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) {