Commit 3cf31507 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline

ThreadUtils: add thread ID support

parent 6ea82531
Pipeline #2957 passed with stages
in 3 minutes and 22 seconds
......@@ -101,6 +101,9 @@ class LIMACORE_API Cond
};
pid_t GetThreadID();
class LIMACORE_API Thread
{
public:
......@@ -113,6 +116,8 @@ class LIMACORE_API Thread
bool hasStarted();
bool hasFinished();
pid_t getThreadID();
protected:
class LIMACORE_API ExceptionCleanUp
{
......@@ -127,6 +132,7 @@ class LIMACORE_API Thread
pthread_attr_t m_thread_attr;
pthread_t m_thread;
pid_t m_tid;
private:
friend class ExceptionCleanUp;
......
......@@ -28,6 +28,8 @@
#else
#include <time_compat.h>
#endif
#include <unistd.h>
#include <sys/syscall.h>
using namespace lima;
......@@ -216,6 +218,10 @@ void Cond::broadcast()
throw LIMA_COM_EXC(Error, "Error broadcast condition");
}
pid_t lima::GetThreadID() {
return syscall(SYS_gettid);
}
Thread::ExceptionCleanUp::ExceptionCleanUp(Thread& thread)
: m_thread(thread)
{
......@@ -229,6 +235,7 @@ Thread::ExceptionCleanUp::~ExceptionCleanUp()
Thread::Thread()
{
m_started = m_finished = m_exception_handled = false;
m_tid = 0;
pthread_attr_init(&m_thread_attr);
}
......@@ -270,11 +277,17 @@ bool Thread::hasFinished()
return m_finished;
}
pid_t Thread::getThreadID()
{
return m_tid;
}
void *Thread::staticThreadFunction(void *data)
{
using namespace std;
Thread *thread = (Thread *) data;
thread->m_tid = GetThreadID();
try {
thread->threadFunction();
......@@ -294,7 +307,6 @@ void *Thread::staticThreadFunction(void *data)
return NULL;
}
CmdThread::AuxThread::AuxThread(CmdThread& master)
: m_master(&master)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment