Skip to content

Commit

Permalink
Assigned proper debug names to internal threads
Browse files Browse the repository at this point in the history
  • Loading branch information
dkargin committed Oct 29, 2024
1 parent 870cd4c commit 49136b5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/miniros/transport/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace miniros
typedef std::map<std::string, std::string> M_string;

void disableAllSignalsInThisThread();
void setThreadName(const char* name);

}

Expand Down
29 changes: 26 additions & 3 deletions src/transport/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,28 @@
*/

#include "miniros/transport/common.h"

#include <cstdlib>
#include <cstdio>
#include <cerrno>
#include <cassert>
#include <sys/types.h>
#if !defined(WIN32)

#if defined(WIN32)
#else
#include <unistd.h>
#include <pthread.h>
#endif

#ifdef __linux__
#include <sys/prctl.h>
#endif

#include <signal.h>

using std::string;
namespace miniros {

void miniros::disableAllSignalsInThisThread()
void disableAllSignalsInThisThread()
{
#if !defined(WIN32)
// pthreads_win32, despite having an implementation of pthread_sigmask,
Expand All @@ -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
1 change: 1 addition & 0 deletions src/transport/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ void basicSigintHandler(int sig)

void internalCallbackQueueThreadFunc()
{
setThreadName("ROS::internalCallbackQueue");
disableAllSignalsInThisThread();

CallbackQueuePtr queue = getInternalCallbackQueue();
Expand Down
1 change: 1 addition & 0 deletions src/transport/poll_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void PollManager::shutdown()

void PollManager::threadFunc()
{
setThreadName("PollManager");
disableAllSignalsInThisThread();

while (!shutting_down_)
Expand Down
1 change: 1 addition & 0 deletions src/transport/rosout_appender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/transport/xmlrpc_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ bool XMLRPCManager::validateXmlrpcResponse(const std::string& method, XmlRpcValu
void XMLRPCManager::serverThreadFunc()
{
disableAllSignalsInThisThread();
setThreadName("XMLRPCManager");

while(!shutting_down_)
{
Expand Down

0 comments on commit 49136b5

Please sign in to comment.