Added static function for current OS thread ID. (#2466)

This commit is contained in:
tomaz-beltram
2018-09-17 16:07:40 +02:00
committed by Aleksandar Fabijanic
parent 98246b2db6
commit 18f3a48fe7
7 changed files with 38 additions and 2 deletions

View File

@@ -214,6 +214,9 @@ public:
static TID currentTid();
/// Returns the native thread ID for the current thread.
static long currentOsTid();
/// Returns the operating system specific thread ID for the current thread.
protected:
ThreadLocalStorage& tls();
/// Returns a reference to the thread's local storage.
@@ -373,6 +376,12 @@ inline Thread::TID Thread::currentTid()
}
inline long Thread::currentOsTid()
{
return currentOsTidImpl();
}
} // namespace Poco

View File

@@ -84,6 +84,7 @@ public:
static void yieldImpl();
static ThreadImpl* currentImpl();
static TIDImpl currentTidImpl();
static long currentOsTidImpl();
protected:
static void* runnableEntry(void* pThread);

View File

@@ -33,7 +33,7 @@ int main(int argc, char** argv)
{
// set up two channel chains - one to the
// console and the other one to a log file.
AutoPtr<PatternFormatter> pPatternFormatter(new PatternFormatter("%s: %p: %t"));
AutoPtr<PatternFormatter> pPatternFormatter(new PatternFormatter("[%O] %s: %p: %t"));
AutoPtr<FormattingChannel> pFCConsole(new FormattingChannel(pPatternFormatter));
AutoPtr<ConsoleChannel> pConsoleChannel(new ConsoleChannel());
pFCConsole->setChannel(pConsoleChannel);

View File

@@ -92,6 +92,7 @@ Message::Message(Message&& msg) :
_prio(std::move(msg._prio)),
_time(std::move(msg._time)),
_tid(std::move(msg._tid)),
_ostid(std::move(msg._ostid)),
_thread(std::move(msg._thread)),
_pid(std::move(msg._pid)),
_file(std::move(msg._file)),
@@ -132,7 +133,7 @@ void Message::init()
#if !defined(POCO_VXWORKS)
_pid = Process::id();
#endif
_ostid = (IntPtr)Thread::currentTid();
_ostid = (IntPtr)Thread::currentOsTid();
Thread* pThread = Thread::current();
if (pThread)
{
@@ -162,6 +163,7 @@ Message& Message::operator = (Message&& msg)
_prio = std::move(msg._prio);
_time = std::move(msg._time);
_tid = std::move(msg._tid);
_ostid = std::move(msg._ostid);
_thread = std::move(msg._thread);
_pid = std::move(msg._pid);
_file = std::move(msg._file);
@@ -182,6 +184,7 @@ void Message::swap(Message& msg)
swap(_prio, msg._prio);
swap(_time, msg._time);
swap(_tid, msg._tid);
swap(_ostid, msg._ostid);
swap(_thread, msg._thread);
swap(_pid, msg._pid);
swap(_file, msg._file);

View File

@@ -237,5 +237,16 @@ int ThreadImpl::getAffinityImpl() const
return cpuSet;
}
long ThreadImpl::currentOsTidImpl()
{
#if POCO_OS == POCO_OS_LINUX
return syscall(SYS_gettid);
#elif POCO_OS == POCO_OS_MAC_OS_X
return pthread_mach_thread_np(pthread_self());
#else
return pthread_self();
#endif
}
} // namespace Poco

View File

@@ -84,4 +84,10 @@ int ThreadImpl::getAffinityImpl() const
}
long ThreadImpl::currentOsTidImpl()
{
return taskIdSelf();
}
} // namespace Poco

View File

@@ -85,4 +85,10 @@ int ThreadImpl::getAffinityImpl() const
}
long ThreadImpl::currentOsTidImpl()
{
return GetCurrentThreadId();
}
} // namespace Poco