add support to textually name threads;

pull/42/head
Bryan Biedenkapp 2 years ago
parent 4e758bba91
commit 07084269aa

@ -30,6 +30,8 @@
*/
#include "Thread.h"
#include <sys/prctl.h>
#include <signal.h>
#include <unistd.h>
// ---------------------------------------------------------------------------
@ -75,6 +77,21 @@ void Thread::wait()
::pthread_join(m_thread, NULL);
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
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
}
/// <summary>
///
/// </summary>

@ -33,6 +33,7 @@
#include "Defines.h"
#include <string>
#include <pthread.h>
// ---------------------------------------------------------------------------
@ -56,6 +57,9 @@ public:
/// <summary></summary>
virtual void wait();
/// <summary></summary>
virtual void setName(std::string name);
/// <summary></summary>
static void sleep(uint32_t ms);

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

Loading…
Cancel
Save

Powered by TurnKey Linux.