diff options
author | Andrej Rode <andrej.rode@ettus.com> | 2017-04-18 16:46:44 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-06-29 13:43:05 -0700 |
commit | c33928d2bbdd27688c3475e77fc461e7d16eba5a (patch) | |
tree | d5bffc49696e2bc03c9b8576864e387373b950fb /host/include | |
parent | 47cdd6319c74a7b823843aad5ff3fa370ed1e6ef (diff) | |
download | uhd-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/include')
-rw-r--r-- | host/include/uhd/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/include/uhd/utils/tasks.hpp | 6 | ||||
-rw-r--r-- | host/include/uhd/utils/thread.hpp | 70 | ||||
-rw-r--r-- | host/include/uhd/utils/thread_priority.hpp | 42 |
4 files changed, 79 insertions, 40 deletions
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index cf5bb8aa8..e176f2c77 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -39,6 +39,7 @@ UHD_INSTALL(FILES static.hpp tasks.hpp thread_priority.hpp + thread.hpp DESTINATION ${INCLUDE_DIR}/uhd/utils COMPONENT headers ) diff --git a/host/include/uhd/utils/tasks.hpp b/host/include/uhd/utils/tasks.hpp index 9b17ae08a..94bc508a1 100644 --- a/host/include/uhd/utils/tasks.hpp +++ b/host/include/uhd/utils/tasks.hpp @@ -40,9 +40,13 @@ namespace uhd{ * It may not block, or the destructor will also block. * * \param task_fcn the task callback function + * \param name Task name. Will be used as a thread name. * \return a new task object */ - static sptr make(const task_fcn_type &task_fcn); + static sptr make( + const task_fcn_type &task_fcn, + const std::string &name="" + ); }; } //namespace uhd diff --git a/host/include/uhd/utils/thread.hpp b/host/include/uhd/utils/thread.hpp new file mode 100644 index 000000000..23268fa01 --- /dev/null +++ b/host/include/uhd/utils/thread.hpp @@ -0,0 +1,70 @@ +// +// Copyright 2010,2017 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#ifndef INCLUDED_UHD_UTILS_THREAD_HPP +#define INCLUDED_UHD_UTILS_THREAD_HPP + +#include <uhd/config.hpp> +#include <boost/thread/thread.hpp> +#include <string> + +namespace uhd{ + + static const float default_thread_priority = float(0.5); + + /*! + * Set the scheduling priority on the current thread. + * + * A new thread or calling process should make this call + * with the defaults this to enable realtime scheduling. + * + * A priority of zero corresponds to normal priority. + * Positive priority values are higher than normal. + * Negative priority values are lower than normal. + * + * \param priority a value between -1 and 1 + * \param realtime true to use realtime mode + * \throw exception on set priority failure + */ + UHD_API void set_thread_priority( + float priority = default_thread_priority, + bool realtime = true + ); + + /*! + * Set the scheduling priority on the current thread. + * Same as set_thread_priority but does not throw on failure. + * \return true on success, false on failure + */ + UHD_API bool set_thread_priority_safe( + float priority = default_thread_priority, + bool realtime = true + ); + + /*! + * Set the thread name on the given boost thread. + * \param thread pointer to a boost thread + * \param name thread name with maximum length of 16 characters + */ + UHD_API void set_thread_name( + boost::thread *thread, + const std::string &name + ); + +} //namespace uhd + +#endif /* INCLUDED_UHD_UTILS_THREAD_HPP */ diff --git a/host/include/uhd/utils/thread_priority.hpp b/host/include/uhd/utils/thread_priority.hpp index c34ac5542..e9012c742 100644 --- a/host/include/uhd/utils/thread_priority.hpp +++ b/host/include/uhd/utils/thread_priority.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010,2017 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -17,42 +17,6 @@ #ifndef INCLUDED_UHD_UTILS_THREAD_PRIORITY_HPP #define INCLUDED_UHD_UTILS_THREAD_PRIORITY_HPP - -#include <uhd/config.hpp> - -namespace uhd{ - - static const float default_thread_priority = float(0.5); - - /*! - * Set the scheduling priority on the current thread. - * - * A new thread or calling process should make this call - * with the defaults this to enable realtime scheduling. - * - * A priority of zero corresponds to normal priority. - * Positive priority values are higher than normal. - * Negative priority values are lower than normal. - * - * \param priority a value between -1 and 1 - * \param realtime true to use realtime mode - * \throw exception on set priority failure - */ - UHD_API void set_thread_priority( - float priority = default_thread_priority, - bool realtime = true - ); - - /*! - * Set the scheduling priority on the current thread. - * Same as set_thread_priority but does not throw on failure. - * \return true on success, false on failure - */ - UHD_API bool set_thread_priority_safe( - float priority = default_thread_priority, - bool realtime = true - ); - -} //namespace uhd - +#pragma message "This header is deprecated - please use <uhd/utils/thread.hpp> instead." +#include <uhd/utils/thread.hpp> #endif /* INCLUDED_UHD_UTILS_THREAD_PRIORITY_HPP */ |