diff --git a/src/Thread.cpp b/src/Thread.cpp index a7db173e..de575d0d 100644 --- a/src/Thread.cpp +++ b/src/Thread.cpp @@ -30,6 +30,8 @@ */ #include "Thread.h" +#include +#include #include // --------------------------------------------------------------------------- @@ -75,6 +77,21 @@ void Thread::wait() ::pthread_join(m_thread, NULL); } +/// +/// +/// +/// +void Thread::setName(std::string name) +{ + if (!m_started) + return; + if (pthread_kill(m_thread, 0) != 0) + return; +#ifdef _GNU_SOURCE + ::pthread_setname_np(m_thread, name.c_str()); +#endif // _GNU_SOURCE +} + /// /// /// diff --git a/src/Thread.h b/src/Thread.h index 593be795..40ea4f6e 100644 --- a/src/Thread.h +++ b/src/Thread.h @@ -33,6 +33,7 @@ #include "Defines.h" +#include #include // --------------------------------------------------------------------------- @@ -56,6 +57,9 @@ public: /// virtual void wait(); + /// + virtual void setName(std::string name); + /// static void sleep(uint32_t ms); diff --git a/src/host/Host.cpp b/src/host/Host.cpp index 73bbd7bf..73732a20 100644 --- a/src/host/Host.cpp +++ b/src/host/Host.cpp @@ -830,6 +830,7 @@ int Host::run() #endif // defined(ENABLE_DMR) }); dmrFrameReadThread.run(); + dmrFrameReadThread.setName("dmr:frame-r"); ThreadFunc dmrFrameWriteThread([&, this]() { #if defined(ENABLE_DMR) @@ -890,6 +891,7 @@ int Host::run() #endif // defined(ENABLE_DMR) }); dmrFrameWriteThread.run(); + dmrFrameWriteThread.setName("dmr:frame-w"); /** Project 25 */ ThreadFunc p25FrameReadThread([&, this]() { @@ -931,6 +933,7 @@ int Host::run() #endif // defined(ENABLE_P25) }); p25FrameReadThread.run(); + p25FrameReadThread.setName("p25:frame-r"); ThreadFunc p25FrameWriteThread([&, this]() { #if defined(ENABLE_P25) @@ -971,6 +974,7 @@ int Host::run() #endif // defined(ENABLE_P25) }); p25FrameWriteThread.run(); + p25FrameWriteThread.setName("p25:frame-w"); /** Next Generation Digital Narrowband */ ThreadFunc nxdnFrameReadThread([&, this]() { @@ -1012,6 +1016,7 @@ int Host::run() #endif // defined(ENABLE_NXDN) }); nxdnFrameReadThread.run(); + nxdnFrameReadThread.setName("nxdn:frame-r"); ThreadFunc nxdnFrameWriteThread([&, this]() { #if defined(ENABLE_NXDN) @@ -1052,6 +1057,7 @@ int Host::run() #endif // defined(ENABLE_NXDN) }); nxdnFrameWriteThread.run(); + nxdnFrameWriteThread.setName("nxdn:frame-w"); // main execution loop while (!killed) {