aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-06-16 19:18:06 -0700
committerJosh Blum <josh@joshknows.com>2010-06-16 19:18:06 -0700
commit339aa3ccd4a50de5e259078635ddbcd552fff22f (patch)
treea2b3da46de6de1d5a9684d82ae99e1e70a2c0986
parent168ab7279cec925e3db3e943e35d0d2bd220d8b3 (diff)
downloaduhd-339aa3ccd4a50de5e259078635ddbcd552fff22f.tar.gz
uhd-339aa3ccd4a50de5e259078635ddbcd552fff22f.tar.bz2
uhd-339aa3ccd4a50de5e259078635ddbcd552fff22f.zip
uhd: working windows implementation of thread priority setting, added called to example apps
-rw-r--r--host/examples/rx_timed_samples.cpp3
-rw-r--r--host/examples/tx_timed_samples.cpp3
-rw-r--r--host/lib/thread_priority.cpp10
3 files changed, 14 insertions, 2 deletions
diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp
index 64da260d5..6920b34d1 100644
--- a/host/examples/rx_timed_samples.cpp
+++ b/host/examples/rx_timed_samples.cpp
@@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/usrp/simple_usrp.hpp>
#include <boost/program_options.hpp>
@@ -25,6 +26,8 @@
namespace po = boost::program_options;
int UHD_SAFE_MAIN(int argc, char *argv[]){
+ uhd::set_thread_priority_safe();
+
//variables to be set by po
std::string args;
int seconds_in_future;
diff --git a/host/examples/tx_timed_samples.cpp b/host/examples/tx_timed_samples.cpp
index e9e0c785e..28fd2ee67 100644
--- a/host/examples/tx_timed_samples.cpp
+++ b/host/examples/tx_timed_samples.cpp
@@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/usrp/simple_usrp.hpp>
#include <boost/program_options.hpp>
@@ -25,6 +26,8 @@
namespace po = boost::program_options;
int UHD_SAFE_MAIN(int argc, char *argv[]){
+ uhd::set_thread_priority_safe();
+
//variables to be set by po
std::string args;
int seconds_in_future;
diff --git a/host/lib/thread_priority.cpp b/host/lib/thread_priority.cpp
index ff3c1528b..afaa5e36e 100644
--- a/host/lib/thread_priority.cpp
+++ b/host/lib/thread_priority.cpp
@@ -76,9 +76,15 @@ static void check_priority_range(float priority){
if (SetPriorityClass(GetCurrentProcess(), pri_class) == 0)
throw std::runtime_error("error in SetPriorityClass");
+ //scale the priority value to the constants
+ int priorities[] = {
+ THREAD_PRIORITY_IDLE, THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_BELOW_NORMAL, THREAD_PRIORITY_NORMAL,
+ THREAD_PRIORITY_ABOVE_NORMAL, THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_TIME_CRITICAL
+ };
+ size_t pri_index = size_t((priority+1.0)*6/2.0); // -1 -> 0, +1 -> 6
+
//set the thread priority on the thread
- int pri_int = int(pri*(THREAD_PRIORITY_TIME_CRITICAL - THREAD_PRIORITY_IDLE)) + THREAD_PRIORITY_IDLE;
- if (SetThreadPriority(GetCurrentThread(), pri_int) == 0)
+ if (SetThreadPriority(GetCurrentThread(), priorities[pri_index]) == 0)
throw std::runtime_error("error in SetThreadPriority");
}