From 339aa3ccd4a50de5e259078635ddbcd552fff22f Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 16 Jun 2010 19:18:06 -0700 Subject: uhd: working windows implementation of thread priority setting, added called to example apps --- host/lib/thread_priority.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'host/lib/thread_priority.cpp') 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"); } -- cgit v1.2.3