diff --git a/include/miniros/transport/common.h b/include/miniros/transport/common.h index a1a361a..294023d 100644 --- a/include/miniros/transport/common.h +++ b/include/miniros/transport/common.h @@ -44,6 +44,7 @@ namespace miniros typedef std::map M_string; void disableAllSignalsInThisThread(); +void setThreadName(const char* name); } diff --git a/src/transport/common.cpp b/src/transport/common.cpp index ce38aa1..3440447 100644 --- a/src/transport/common.cpp +++ b/src/transport/common.cpp @@ -33,20 +33,28 @@ */ #include "miniros/transport/common.h" + #include #include #include #include #include -#if !defined(WIN32) + +#if defined(WIN32) +#else #include #include #endif + +#ifdef __linux__ +#include +#endif + #include -using std::string; +namespace miniros { -void miniros::disableAllSignalsInThisThread() +void disableAllSignalsInThisThread() { #if !defined(WIN32) // pthreads_win32, despite having an implementation of pthread_sigmask, @@ -59,3 +67,18 @@ void miniros::disableAllSignalsInThisThread() pthread_sigmask( SIG_BLOCK, &signal_set, NULL ); #endif } + +// Following advice at https://stackoverflow.com/questions/10121560/stdthread-naming-your-thread +void setThreadName(const char* threadName) { +#if defined(WIN32) + + // TODO: Implement. +#elif defined(__linux__) + prctl(PR_SET_NAME, threadName,0,0,0); +#else + pthread_t handle = pthread_self(); + pthread_setname_np(handle, threadName); +#endif +} + +} // namespace miniros diff --git a/src/transport/init.cpp b/src/transport/init.cpp index 68ece5a..a994744 100644 --- a/src/transport/init.cpp +++ b/src/transport/init.cpp @@ -288,6 +288,7 @@ void basicSigintHandler(int sig) void internalCallbackQueueThreadFunc() { + setThreadName("ROS::internalCallbackQueue"); disableAllSignalsInThisThread(); CallbackQueuePtr queue = getInternalCallbackQueue(); diff --git a/src/transport/poll_manager.cpp b/src/transport/poll_manager.cpp index 8ed0de0..28b14fb 100644 --- a/src/transport/poll_manager.cpp +++ b/src/transport/poll_manager.cpp @@ -71,6 +71,7 @@ void PollManager::shutdown() void PollManager::threadFunc() { + setThreadName("PollManager"); disableAllSignalsInThisThread(); while (!shutting_down_) diff --git a/src/transport/rosout_appender.cpp b/src/transport/rosout_appender.cpp index 03b8599..86178c1 100644 --- a/src/transport/rosout_appender.cpp +++ b/src/transport/rosout_appender.cpp @@ -125,6 +125,7 @@ void ROSOutAppender::log(::miniros::console::Level level, const char* str, const void ROSOutAppender::logThread() { + setThreadName("ROSOutAppender"); while (!shutting_down_) { V_Log local_queue; diff --git a/src/transport/xmlrpc_manager.cpp b/src/transport/xmlrpc_manager.cpp index 5787c9d..ea84960 100644 --- a/src/transport/xmlrpc_manager.cpp +++ b/src/transport/xmlrpc_manager.cpp @@ -249,6 +249,7 @@ bool XMLRPCManager::validateXmlrpcResponse(const std::string& method, XmlRpcValu void XMLRPCManager::serverThreadFunc() { disableAllSignalsInThisThread(); + setThreadName("XMLRPCManager"); while(!shutting_down_) {