aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/utils/tasks.cpp
diff options
context:
space:
mode:
authorAndrej Rode <andrej.rode@ettus.com>2017-04-18 16:46:44 -0700
committerMartin Braun <martin.braun@ettus.com>2017-06-29 13:43:05 -0700
commitc33928d2bbdd27688c3475e77fc461e7d16eba5a (patch)
treed5bffc49696e2bc03c9b8576864e387373b950fb /host/lib/utils/tasks.cpp
parent47cdd6319c74a7b823843aad5ff3fa370ed1e6ef (diff)
downloaduhd-c33928d2bbdd27688c3475e77fc461e7d16eba5a.tar.gz
uhd-c33928d2bbdd27688c3475e77fc461e7d16eba5a.tar.bz2
uhd-c33928d2bbdd27688c3475e77fc461e7d16eba5a.zip
utils: add set_thread_name API call, move thread_priority to thread
Diffstat (limited to 'host/lib/utils/tasks.cpp')
-rw-r--r--host/lib/utils/tasks.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/host/lib/utils/tasks.cpp b/host/lib/utils/tasks.cpp
index 38d19502e..fb9a3052e 100644
--- a/host/lib/utils/tasks.cpp
+++ b/host/lib/utils/tasks.cpp
@@ -17,6 +17,7 @@
#include <uhd/utils/tasks.hpp>
#include <uhd/utils/msg_task.hpp>
+#include <uhd/utils/thread.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/exception.hpp>
#include <boost/thread/thread.hpp>
@@ -32,10 +33,15 @@ using namespace uhd;
class task_impl : public task{
public:
- task_impl(const task_fcn_type &task_fcn):
+ task_impl(const task_fcn_type &task_fcn, const std::string &name):
_exit(false)
{
_task = std::thread([this, task_fcn](){ this->task_loop(task_fcn); });
+ if (not name.empty()) {
+#ifdef HAVE_PTHREAD_SETNAME
+ pthread_setname_np(_task->native_handle(), name.substr(0,16).c_str());
+#endif /* HAVE_PTHREAD_SETNAME */
+ }
}
~task_impl(void){
@@ -46,7 +52,6 @@ public:
}
private:
-
void task_loop(const task_fcn_type &task_fcn){
try{
while (!_exit){
@@ -73,8 +78,8 @@ private:
std::thread _task;
};
-task::sptr task::make(const task_fcn_type &task_fcn){
- return task::sptr(new task_impl(task_fcn));
+task::sptr task::make(const task_fcn_type &task_fcn, const std::string &name){
+ return task::sptr(new task_impl(task_fcn, name));
}
msg_task::~msg_task(void){