summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib/thread/thread.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime/lib/thread/thread.cc')
-rw-r--r--gnuradio-runtime/lib/thread/thread.cc22
1 files changed, 11 insertions, 11 deletions
diff --git a/gnuradio-runtime/lib/thread/thread.cc b/gnuradio-runtime/lib/thread/thread.cc
index 8c59b6df74..e393ae5438 100644
--- a/gnuradio-runtime/lib/thread/thread.cc
+++ b/gnuradio-runtime/lib/thread/thread.cc
@@ -124,20 +124,20 @@ namespace gr {
set_thread_name(gr_thread_t thread, std::string name)
{
const DWORD SET_THREAD_NAME_EXCEPTION = 0x406D1388;
-
+
DWORD dwThreadId = GetThreadId(thread);
if (dwThreadId == 0)
return;
-
+
if (name.empty())
name = boost::str(boost::format("thread %lu") % dwThreadId);
-
+
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name.c_str();
info.dwThreadID = dwThreadId;
info.dwFlags = 0;
-
+
__try
{
RaiseException(SET_THREAD_NAME_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info);
@@ -221,7 +221,7 @@ namespace gr {
param.sched_priority = priority;
return pthread_setschedparam(thread, policy, &param);
}
-
+
void
set_thread_name(gr_thread_t thread, std::string name)
{
@@ -334,18 +334,18 @@ namespace gr {
param.sched_priority = priority;
return pthread_setschedparam(thread, policy, &param);
}
-
+
void
set_thread_name(gr_thread_t thread, std::string name)
{
if (thread != pthread_self()) // Naming another thread is not supported
return;
-
+
if (name.empty())
name = boost::str(boost::format("thread %llu") % ((unsigned long long)thread));
-
+
const int max_len = 16; // Maximum accepted by PR_SET_NAME
-
+
if ((int)name.size() > max_len) // Shorten the name if necessary by taking as many characters from the front
{ // so that the unique_id can still fit on the end
int i = name.size() - 1;
@@ -356,10 +356,10 @@ namespace gr {
if ((n == 0) && (s != "0"))
break;
}
-
+
name = name.substr(0, std::max(0, max_len - ((int)name.size() - (i + 1)))) + name.substr(i + 1);
}
-
+
prctl(PR_SET_NAME, name.c_str(), 0, 0, 0);
}