Commit 3b4e4b45 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron

Merge branch 'add_thread_id' into 'master'

ThreadUtils: add thread ID support

See merge request !60
parents 6ea82531 c52d902d
Pipeline #3091 passed with stages
in 1 minute and 37 seconds
......@@ -28,6 +28,11 @@
#include <bitset>
#include <queue>
#if defined(_WIN32)
#include <WinBase.h>
#define pid_t DWORD
#endif
namespace lima
{
......@@ -101,6 +106,9 @@ class LIMACORE_API Cond
};
pid_t GetThreadID();
class LIMACORE_API Thread
{
public:
......@@ -113,6 +121,8 @@ class LIMACORE_API Thread
bool hasStarted();
bool hasFinished();
pid_t getThreadID();
protected:
class LIMACORE_API ExceptionCleanUp
{
......@@ -127,6 +137,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,11 @@
#else
#include <time_compat.h>
#endif
#include <unistd.h>
#if !defined(_WIN32)
#include <sys/syscall.h>
#endif
using namespace lima;
......@@ -216,6 +221,16 @@ void Cond::broadcast()
throw LIMA_COM_EXC(Error, "Error broadcast condition");
}
pid_t lima::GetThreadID() {
#if defined(_WIN32)
return GetCurrentThreadId();
#else
return syscall(SYS_gettid);
#endif
}
Thread::ExceptionCleanUp::ExceptionCleanUp(Thread& thread)
: m_thread(thread)
{
......@@ -229,6 +244,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 +286,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 +316,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