summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/lib
diff options
context:
space:
mode:
authorTim O'Shea <tim.oshea753@gmail.com>2013-06-05 10:52:22 -0400
committerTim O'Shea <tim.oshea753@gmail.com>2013-06-05 14:20:37 -0400
commit2df6f769ce2cd026d92778ded780941ac3a0da0c (patch)
tree6ae067e8e75fdd65f97755690cd483fe592304ba /gnuradio-runtime/lib
parent9c154832f1db9a7cc0a8ebe33e8798541335caf1 (diff)
runtime: adding thread priority methods to gr::block
Diffstat (limited to 'gnuradio-runtime/lib')
-rw-r--r--gnuradio-runtime/lib/block.cc28
-rw-r--r--gnuradio-runtime/lib/block_detail.cc16
-rw-r--r--gnuradio-runtime/lib/thread/thread.cc50
-rw-r--r--gnuradio-runtime/lib/tpb_thread_body.cc5
4 files changed, 98 insertions, 1 deletions
diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc
index 4246180d80..0165365b9e 100644
--- a/gnuradio-runtime/lib/block.cc
+++ b/gnuradio-runtime/lib/block.cc
@@ -50,7 +50,8 @@ namespace gr {
d_tag_propagation_policy(TPP_ALL_TO_ALL),
d_pc_rpc_set(false),
d_max_output_buffer(std::max(output_signature->max_streams(),1), -1),
- d_min_output_buffer(std::max(output_signature->max_streams(),1), -1)
+ d_min_output_buffer(std::max(output_signature->max_streams(),1), -1),
+ d_priority(-1)
{
global_block_registry.register_primitive(alias(), this);
@@ -318,6 +319,31 @@ namespace gr {
}
}
+ int
+ block::active_thread_priority()
+ {
+ if(d_detail) {
+ return d_detail->thread_priority();
+ }
+ return -1;
+ }
+
+ int
+ block::thread_priority()
+ {
+ return d_priority;
+ }
+
+ int
+ block::set_thread_priority(int priority)
+ {
+ d_priority = priority;
+ if(d_detail) {
+ return d_detail->set_thread_priority(priority);
+ }
+ return d_priority;
+ }
+
float
block::pc_noutput_items()
{
diff --git a/gnuradio-runtime/lib/block_detail.cc b/gnuradio-runtime/lib/block_detail.cc
index 8d149be848..0be22bf5b7 100644
--- a/gnuradio-runtime/lib/block_detail.cc
+++ b/gnuradio-runtime/lib/block_detail.cc
@@ -240,6 +240,22 @@ namespace gr {
}
}
+ int
+ block_detail::thread_priority(){
+ if(threaded) {
+ return gr::thread::thread_priority(thread);
+ }
+ return -1;
+ }
+
+ int
+ block_detail::set_thread_priority(int priority){
+ if(threaded) {
+ return gr::thread::set_thread_priority(thread,priority);
+ }
+ return -1;
+ }
+
void
block_detail::start_perf_counters()
{
diff --git a/gnuradio-runtime/lib/thread/thread.cc b/gnuradio-runtime/lib/thread/thread.cc
index 1727dc6621..d79d1a0129 100644
--- a/gnuradio-runtime/lib/thread/thread.cc
+++ b/gnuradio-runtime/lib/thread/thread.cc
@@ -97,6 +97,20 @@ namespace gr {
}
}
+ int
+ thread_priority(gr_thread_t thread)
+ {
+ // Not implemented on Windows
+ return -1;
+ }
+
+ int
+ set_thread_priority(gr_thread_t thread, int priority)
+ {
+ // Not implemented on Windows
+ return -1;
+ }
+
} /* namespace thread */
} /* namespace gr */
@@ -148,6 +162,20 @@ namespace gr {
// Not implemented on OSX
}
+ int
+ thread_priority(gr_thread_t thread)
+ {
+ // Not implemented on OSX
+ return -1;
+ }
+
+ int
+ set_thread_priority(gr_thread_t thread, int priority)
+ {
+ // Not implemented on OSX
+ return -1;
+ }
+
} /* namespace thread */
} /* namespace gr */
@@ -232,6 +260,28 @@ namespace gr {
}
}
+ int
+ thread_priority(gr_thread_t thread)
+ {
+ sched_param param;
+ int priority;
+ int policy;
+ int ret;
+ ret = pthread_getschedparam (thread, &policy, &param);
+ priority = param.sched_priority;
+ return (ret==0)?priority:ret;
+ }
+
+ int
+ set_thread_priority(gr_thread_t thread, int priority)
+ {
+ int policy;
+ struct sched_param param;
+ pthread_getschedparam (thread, &policy, &param);
+ param.sched_priority = priority;
+ return pthread_setschedparam(thread, policy, &param);
+ }
+
} /* namespace thread */
} /* namespace gr */
diff --git a/gnuradio-runtime/lib/tpb_thread_body.cc b/gnuradio-runtime/lib/tpb_thread_body.cc
index ceb94fbb2a..c49594c931 100644
--- a/gnuradio-runtime/lib/tpb_thread_body.cc
+++ b/gnuradio-runtime/lib/tpb_thread_body.cc
@@ -52,6 +52,11 @@ namespace gr {
gr::thread::thread_bind_to_processor(d->thread, block->processor_affinity());
}
+ // Set thread priority if it was set before fg was started
+ if(block->thread_priority() > 0) {
+ gr::thread::set_thread_priority(d->thread, block->thread_priority());
+ }
+
while(1) {
boost::this_thread::interruption_point();