aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/include/uhd/utils/thread.hpp8
-rw-r--r--host/lib/utils/thread.cpp12
2 files changed, 20 insertions, 0 deletions
diff --git a/host/include/uhd/utils/thread.hpp b/host/include/uhd/utils/thread.hpp
index c7358040e..05cba0d14 100644
--- a/host/include/uhd/utils/thread.hpp
+++ b/host/include/uhd/utils/thread.hpp
@@ -11,6 +11,7 @@
#include <uhd/config.hpp>
#include <boost/thread/thread.hpp>
#include <string>
+#include <thread>
namespace uhd {
@@ -48,6 +49,13 @@ UHD_API bool set_thread_priority_safe(
*/
UHD_API void set_thread_name(boost::thread* thread, const std::string& name);
+/*!
+ * Set the thread name on the given std thread.
+ * \param thread pointer to a boost thread
+ * \param name thread name with maximum length of 16 characters
+ */
+UHD_API void set_thread_name(std::thread* thread, const std::string& name);
+
} // namespace uhd
#endif /* INCLUDED_UHD_UTILS_THREAD_HPP */
diff --git a/host/lib/utils/thread.cpp b/host/lib/utils/thread.cpp
index 893496243..d8f52c4c8 100644
--- a/host/lib/utils/thread.cpp
+++ b/host/lib/utils/thread.cpp
@@ -110,3 +110,15 @@ void uhd::set_thread_name(
UHD_LOG_DEBUG("UHD", "Setting thread name is not implemented; wanted to set to " << name);
#endif /* HAVE_THREAD_SETNAME_DUMMY */
}
+
+void uhd::set_thread_name(
+ std::thread *thrd,
+ const std::string &name
+) {
+#ifdef HAVE_PTHREAD_SETNAME
+ pthread_setname_np(thrd->native_handle(), name.substr(0,16).c_str());
+#endif /* HAVE_PTHREAD_SETNAME */
+#ifdef HAVE_THREAD_SETNAME_DUMMY
+ UHD_LOG_DEBUG("UHD", "Setting thread name is not implemented; wanted to set to " << name);
+#endif /* HAVE_THREAD_SETNAME_DUMMY */
+}