Merge branch 'develop' of https://github.com/pocoproject/poco into develop

This commit is contained in:
unknown 2015-06-01 10:30:30 -05:00
commit 86301edc09
6 changed files with 55 additions and 3 deletions

View File

@ -128,6 +128,9 @@ public:
long getTid() const;
/// Returns the numeric thread identifier for the message.
long getOsTid() const;
/// Returns the numeric OS thread identifier for the message.
void setPid(long pid);
/// Sets the process identifier for the message.
@ -196,6 +199,7 @@ private:
Priority _prio;
Timestamp _time;
int _tid;
int _ostid;
std::string _thread;
long _pid;
const char* _file;
@ -243,6 +247,12 @@ inline long Message::getTid() const
}
inline long Message::getOsTid() const
{
return _ostid;
}
inline long Message::getPid() const
{
return _pid;

View File

@ -45,6 +45,7 @@ class Foundation_API PatternFormatter: public Formatter
/// * %P - message process identifier
/// * %T - message thread name
/// * %I - message thread identifier (numeric)
/// * %O - message thread OS identifier (numeric)
/// * %N - node or host name
/// * %U - message source file path (empty string if not set)
/// * %u - message source line number (0 if not set)

View File

@ -45,7 +45,18 @@ namespace Poco {
class Foundation_API ThreadImpl
{
public:
#if POCO_OS == POCO_OS_LINUX
// OS kernel thread ID
typedef pid_t TIDImpl;
#elif POCO_OS == POCO_OS_MAC_OS_X
// OS kernel thread ID
typedef mach_port_t TIDImpl;
#else
// Default: pthread id
typedef pthread_t TIDImpl;
#endif
typedef void (*Callable)(void*);
enum Priority
@ -136,6 +147,7 @@ private:
SharedPtr<Runnable> pRunnableTarget;
pthread_t thread;
TIDImpl tid;
int prio;
int osPrio;
int policy;
@ -191,7 +203,7 @@ inline int ThreadImpl::getStackSizeImpl() const
inline ThreadImpl::TIDImpl ThreadImpl::tidImpl() const
{
return _pData->thread;
return _pData->tid;
}

View File

@ -29,6 +29,7 @@ namespace Poco {
Message::Message():
_prio(PRIO_FATAL),
_tid(0),
_ostid(0),
_pid(0),
_file(0),
_line(0),
@ -43,6 +44,7 @@ Message::Message(const std::string& source, const std::string& text, Priority pr
_text(text),
_prio(prio),
_tid(0),
_ostid(0),
_pid(0),
_file(0),
_line(0),
@ -57,6 +59,7 @@ Message::Message(const std::string& source, const std::string& text, Priority pr
_text(text),
_prio(prio),
_tid(0),
_ostid(0),
_pid(0),
_file(file),
_line(line),
@ -72,6 +75,7 @@ Message::Message(const Message& msg):
_prio(msg._prio),
_time(msg._time),
_tid(msg._tid),
_ostid(msg._ostid),
_thread(msg._thread),
_pid(msg._pid),
_file(msg._file),
@ -90,6 +94,7 @@ Message::Message(const Message& msg, const std::string& text):
_prio(msg._prio),
_time(msg._time),
_tid(msg._tid),
_ostid(msg._ostid),
_thread(msg._thread),
_pid(msg._pid),
_file(msg._file),
@ -113,6 +118,7 @@ void Message::init()
#if !defined(POCO_VXWORKS)
_pid = Process::id();
#endif
_ostid = Thread::currentTid();
Thread* pThread = Thread::current();
if (pThread)
{

View File

@ -75,6 +75,7 @@ void PatternFormatter::format(const Message& msg, std::string& text)
case 'P': NumberFormatter::append(text, msg.getPid()); break;
case 'T': text.append(msg.getThread()); break;
case 'I': NumberFormatter::append(text, msg.getTid()); break;
case 'O': NumberFormatter::append(text, msg.getOsTid()); break;
case 'N': text.append(Environment::nodeName()); break;
case 'U': text.append(msg.getSourceFile() ? msg.getSourceFile() : ""); break;
case 'u': NumberFormatter::append(text, msg.getSourceLine()); break;

View File

@ -35,7 +35,9 @@
# include <mach/task.h>
# include <mach/thread_policy.h>
#endif
#if POCO_OS == POCO_OS_LINUX
#include <sys/syscall.h>
#endif
//
// Block SIGPIPE in main thread.
@ -296,6 +298,15 @@ void ThreadImpl::startImpl(SharedPtr<Runnable> pTarget)
pthread_attr_destroy(&attributes);
throw SystemException("cannot start thread");
}
#if POCO_OS == POCO_OS_LINUX
// On Linux the TID is acquired from the running thread using syscall
_pData->tid = 0;
#elif POCO_OS == POCO_OS_MAC_OS_X
_pData->tid = static_cast<TIDImpl>( pthread_mach_thread_np(_pData->thread) );
#else
_pData->tid = _pData->thread;
#endif
_pData->started = true;
pthread_attr_destroy(&attributes);
@ -353,7 +364,13 @@ ThreadImpl* ThreadImpl::currentImpl()
ThreadImpl::TIDImpl ThreadImpl::currentTidImpl()
{
#if POCO_OS == POCO_OS_LINUX
return static_cast<TIDImpl>( syscall (SYS_gettid) );
#elif POCO_OS == POCO_OS_MAC_OS_X
return static_cast<TIDImpl>( pthread_mach_thread_np(pthread_self()) );
#else
return pthread_self();
#endif
}
@ -430,7 +447,12 @@ void* ThreadImpl::runnableEntry(void* pThread)
#if defined(POCO_POSIX_DEBUGGER_THREAD_NAMES)
setThreadName(pThreadImpl->_pData->thread, reinterpret_cast<Thread*>(pThread)->getName().c_str());
#endif
#if POCO_OS == POCO_OS_LINUX
pThreadImpl->_pData->tid = static_cast<TIDImpl>( syscall (SYS_gettid) );
#endif
AutoPtr<ThreadData> pData = pThreadImpl->_pData;
try
{
pData->pRunnableTarget->run();