summaryrefslogtreecommitdiff
path: root/gruel/src/lib/realtime.cc
diff options
context:
space:
mode:
authorJosh Blum2011-07-20 17:56:41 -0700
committerJosh Blum2011-07-20 17:56:41 -0700
commited950948ea424f3670be1f5ffc96be922ab5e3c9 (patch)
tree77948c0c2ce7b77ef12e0306f6bd78c29f1395c5 /gruel/src/lib/realtime.cc
parent947ae1cf5c16f5b3c6222b6ee9ad1a3b4075dd25 (diff)
downloadgnuradio-ed950948ea424f3670be1f5ffc96be922ab5e3c9.tar.gz
gnuradio-ed950948ea424f3670be1f5ffc96be922ab5e3c9.tar.bz2
gnuradio-ed950948ea424f3670be1f5ffc96be922ab5e3c9.zip
gruel: support for windows API set realtime scheduling
Diffstat (limited to 'gruel/src/lib/realtime.cc')
-rw-r--r--gruel/src/lib/realtime.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/gruel/src/lib/realtime.cc b/gruel/src/lib/realtime.cc
index 7397cf3d3..96351f812 100644
--- a/gruel/src/lib/realtime.cc
+++ b/gruel/src/lib/realtime.cc
@@ -132,6 +132,38 @@ namespace gruel {
} // namespace gruel
+#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
+
+#include <windows.h>
+
+namespace gruel {
+
+ rt_status_t enable_realtime_scheduling(rt_sched_param p){
+
+ //set the priority class on the process
+ int pri_class = (true)? REALTIME_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS;
+ if (SetPriorityClass(GetCurrentProcess(), pri_class) == 0)
+ return RT_OTHER_ERROR;
+
+ //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
+ };
+ const double priority = double(p.priority)/(rt_priority_max() - rt_priority_min());
+ size_t pri_index = size_t((priority+1.0)*6/2.0); // -1 -> 0, +1 -> 6
+ pri_index %= sizeof(priorities)/sizeof(*priorities); //range check
+
+ //set the thread priority on the thread
+ if (SetThreadPriority(GetCurrentThread(), priorities[pri_index]) == 0)
+ return RT_OTHER_ERROR;
+
+ //printf("SetPriorityClass + SetThreadPriority\n");
+ return RT_OK;
+ }
+
+} // namespace gruel
+
#else
namespace gruel {