review, replacing syscall(sys_gettid) with gettid()

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@
#include <csignal> //SIGINT
#include <semaphore.h>
#include <sys/syscall.h>
#include <unistd.h>
sem_t semaphore;
@ -19,7 +18,7 @@ int main(int argc, char *argv[]) {
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
struct sigaction sa;
@ -50,7 +49,7 @@ int main(int argc, char *argv[]) {
} catch (...) {
// pass
}
LOG(logINFOBLUE) << "Exiting [ Tid: " << syscall(SYS_gettid) << " ]";
LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
LOG(logINFO) << "Exiting Receiver";
return 0;
}

View File

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