Handle noninteger pthread_t.
@@ -39,6 +39,14 @@ char Logger::_hostname[1024] = { '\0'};
char Logger::_serviceName[1024] = {'\0' };
ControlFile *Logger::_controlFile = 0;
+static inline unsigned long gettid(const void *tid) {
+ return reinterpret_cast<uint64_t>(tid) >> 3;
+}
+
+static inline unsigned long gettid(unsigned long tid) {
+ return tid;
+}
+
void
Logger::ensureControlName()
{
@@ -265,7 +273,7 @@ void Logger::doLogCore(uint64_t timestamp, LogLevel level,
// threads, only showing the least significant bits will hopefully
// distinguish between all threads in your application. Alter later if
// found to be too inaccurate.
- int32_t tid = (fakePid ? -1 : pthread_self() % 0xffff);
+ int32_t tid = (fakePid ? -1 : gettid(pthread_self()) % 0xffff);
if (_target->makeHumanReadable()) {
time_t secs = static_cast<time_t>(timestamp / 1000000);
