|
28 | 28 | #endif |
29 | 29 | #if POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_QNX |
30 | 30 | # include <time.h> |
31 | | -# include <unistd.h> |
| 31 | +# include <unistd.h> |
32 | 32 | #endif |
33 | 33 | #if POCO_OS == POCO_OS_MAC_OS_X |
34 | 34 | # include <mach/mach.h> |
35 | 35 | # include <mach/task.h> |
36 | 36 | # include <mach/thread_policy.h> |
37 | 37 | #endif |
38 | | - |
| 38 | +#if POCO_OS == POCO_OS_LINUX |
| 39 | +#include <sys/syscall.h> |
| 40 | +#endif |
39 | 41 |
|
40 | 42 | // |
41 | 43 | // Block SIGPIPE in main thread. |
@@ -296,6 +298,15 @@ void ThreadImpl::startImpl(SharedPtr<Runnable> pTarget) |
296 | 298 | pthread_attr_destroy(&attributes); |
297 | 299 | throw SystemException("cannot start thread"); |
298 | 300 | } |
| 301 | +#if POCO_OS == POCO_OS_LINUX |
| 302 | + // On Linux the TID is acquired from the running thread using syscall |
| 303 | + _pData->tid = 0; |
| 304 | +#elif POCO_OS == POCO_OS_MAC_OS_X |
| 305 | + _pData->tid = static_cast<TIDImpl>( pthread_mach_thread_np(_pData->thread) ); |
| 306 | +#else |
| 307 | + _pData->tid = _pData->thread; |
| 308 | +#endif |
| 309 | + |
299 | 310 | _pData->started = true; |
300 | 311 | pthread_attr_destroy(&attributes); |
301 | 312 |
|
@@ -353,7 +364,13 @@ ThreadImpl* ThreadImpl::currentImpl() |
353 | 364 |
|
354 | 365 | ThreadImpl::TIDImpl ThreadImpl::currentTidImpl() |
355 | 366 | { |
| 367 | +#if POCO_OS == POCO_OS_LINUX |
| 368 | + return static_cast<TIDImpl>( syscall (SYS_gettid) ); |
| 369 | +#elif POCO_OS == POCO_OS_MAC_OS_X |
| 370 | + return static_cast<TIDImpl>( pthread_mach_thread_np(pthread_self()) ); |
| 371 | +#else |
356 | 372 | return pthread_self(); |
| 373 | +#endif |
357 | 374 | } |
358 | 375 |
|
359 | 376 |
|
@@ -430,7 +447,12 @@ void* ThreadImpl::runnableEntry(void* pThread) |
430 | 447 | #if defined(POCO_POSIX_DEBUGGER_THREAD_NAMES) |
431 | 448 | setThreadName(pThreadImpl->_pData->thread, reinterpret_cast<Thread*>(pThread)->getName().c_str()); |
432 | 449 | #endif |
| 450 | +#if POCO_OS == POCO_OS_LINUX |
| 451 | + pThreadImpl->_pData->tid = static_cast<TIDImpl>( syscall (SYS_gettid) ); |
| 452 | +#endif |
| 453 | + |
433 | 454 | AutoPtr<ThreadData> pData = pThreadImpl->_pData; |
| 455 | + |
434 | 456 | try |
435 | 457 | { |
436 | 458 | pData->pRunnableTarget->run(); |
|
0 commit comments