Fixing ThreadNaming.

This commit is contained in:
stephb9959
2022-07-24 09:55:18 -07:00
parent dbf7d5eef7
commit cc84cedd55
3 changed files with 18 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include "Poco/Timespan.h"
#include "Poco/Timestamp.h"
#include <signal.h>
#include <iostream>
#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);

View File

@@ -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)

View File

@@ -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 (;;)