From cc84cedd551db614410ac718ac30f68201898bec Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Sun, 24 Jul 2022 09:55:18 -0700 Subject: [PATCH] Fixing ThreadNaming. --- Foundation/src/Thread_POSIX.cpp | 2 ++ Net/src/TCPServer.cpp | 8 ++++++++ Net/src/TCPServerDispatcher.cpp | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/Foundation/src/Thread_POSIX.cpp b/Foundation/src/Thread_POSIX.cpp index ceab76e82..38aa283ad 100644 --- a/Foundation/src/Thread_POSIX.cpp +++ b/Foundation/src/Thread_POSIX.cpp @@ -19,6 +19,7 @@ #include "Poco/Timespan.h" #include "Poco/Timestamp.h" #include +#include #if defined(__sun) && defined(__SVR4) # if !defined(__EXTENSIONS__) # define __EXTENSIONS__ @@ -70,6 +71,7 @@ void setThreadName(pthread_t thread, const std::string& threadName) #else if (pthread_setname_np(thread, threadName.c_str()) == ERANGE && threadName.size() > 15) { + std::cout << "Calling OS thread name: " << threadName << std::endl; std::string truncName(threadName, 0, 7); truncName.append("~"); truncName.append(threadName, threadName.size() - 7, 7); diff --git a/Net/src/TCPServer.cpp b/Net/src/TCPServer.cpp index be8201cba..7e7f1ab94 100644 --- a/Net/src/TCPServer.cpp +++ b/Net/src/TCPServer.cpp @@ -130,6 +130,14 @@ void TCPServer::run() if(!_pDispatcher->params().getName().empty()) { std::cout << "Setting thread name: " << _pDispatcher->params().getName() << std::endl; Poco::Thread::current()->setName(_pDispatcher->params().getName()); +#ifdef __linux__ + Poco::Thread::current()->setName(_pDispatcher->params().getName()); + pthread_setname_np(pthread_self(), _pDispatcher->params().getName().c_str()); +#endif +#ifdef __APPLE__ + Poco::Thread::current()->setName(_pDispatcher->params().getName()); + pthread_setname_np(_pDispatcher->params().getName().c_str()); +#endif } while (!_stopped) diff --git a/Net/src/TCPServerDispatcher.cpp b/Net/src/TCPServerDispatcher.cpp index aca9b3a47..58e9e4707 100644 --- a/Net/src/TCPServerDispatcher.cpp +++ b/Net/src/TCPServerDispatcher.cpp @@ -104,6 +104,14 @@ void TCPServerDispatcher::run() if(!_pParams->getName().empty()) { std::cout << "Setting thread name: " << _pParams->getName() << std::endl; Poco::Thread::current()->setName(_pParams->getName()); +#ifdef __linux__ + Poco::Thread::current()->setName_pParams->getName()); + pthread_setname_np(pthread_self(), _pParams->getName().c_str()); +#endif +#ifdef __APPLE__ + Poco::Thread::current()->setName(_pParams->getName()); + pthread_setname_np(_pParams->getName().c_str()); +#endif } for (;;)