summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------gnuradio0
-rw-r--r--include/gras/thread_pool.hpp11
-rw-r--r--lib/block_actor.cpp2
-rw-r--r--lib/thread_pool.cpp37
-rw-r--r--tests/thread_pool_test.py4
5 files changed, 52 insertions, 2 deletions
diff --git a/gnuradio b/gnuradio
-Subproject 89ef118890bcd5df8441be95dfe70a90f39d3bd
+Subproject 2c0627d07360e31bb25ac334d349eb52e27086f
diff --git a/include/gras/thread_pool.hpp b/include/gras/thread_pool.hpp
index e62da3a..2d25178 100644
--- a/include/gras/thread_pool.hpp
+++ b/include/gras/thread_pool.hpp
@@ -83,6 +83,17 @@ struct GRAS_API ThreadPool : boost::shared_ptr<Theron::Framework>
* thread pool that the block's work routine will run in.
*/
void set_active(void);
+
+ /*!
+ * Test that a particular thread priority setting is possible.
+ *
+ * Highly OS dependent! Some OS require special permissions,
+ * or security settings to use real time priority setting.
+ *
+ * \param thread_priority range -1.0f to 1.0f, 0.0f is "normal"
+ * \return true if the priority change is possible
+ */
+ static bool test_thread_priority(const float thread_priority);
};
} //namespace gras
diff --git a/lib/block_actor.cpp b/lib/block_actor.cpp
index 3ce7742..464167f 100644
--- a/lib/block_actor.cpp
+++ b/lib/block_actor.cpp
@@ -3,7 +3,7 @@
#include <gras/thread_pool.hpp>
#include <gras_impl/block_actor.hpp>
#include <Theron/Framework.h>
-#include <stdexcept>
+#include <iostream>
using namespace gras;
diff --git a/lib/thread_pool.cpp b/lib/thread_pool.cpp
index cd5c320..05c5bda 100644
--- a/lib/thread_pool.cpp
+++ b/lib/thread_pool.cpp
@@ -1,10 +1,12 @@
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
#include <gras/thread_pool.hpp>
-#include <boost/thread/thread.hpp>
+#include <boost/thread.hpp> //mutex, thread, hardware_concurrency
#include <Theron/EndPoint.h>
#include <Theron/Framework.h>
+#include <Theron/Detail/Threading/Utils.h> //prio test
#include <stdexcept>
+#include <iostream>
using namespace gras;
@@ -55,3 +57,36 @@ ThreadPool::ThreadPool(const ThreadPoolConfig &config)
this->reset(new Theron::Framework(Theron::Framework::Parameters(params)));
}
+
+static void test_thread_priority_thread(
+ const float thread_priority,
+ bool &result, bool &called,
+ boost::mutex &mutex
+)
+{
+ std::cout << "Created thread to test priority " << thread_priority << std::endl;
+ result = Theron::Detail::Utils::SetThreadRelativePriority(thread_priority);
+ called = true;
+ mutex.unlock();
+}
+
+bool ThreadPool::test_thread_priority(const float thread_priority)
+{
+ boost::mutex mutex;
+ boost::thread_group thread_group;
+ bool result = false;
+ bool called = false;
+ mutex.lock();
+ thread_group.create_thread(boost::bind(
+ &test_thread_priority_thread,
+ thread_priority,
+ boost::ref(result),
+ boost::ref(called),
+ boost::ref(mutex)
+ ));
+ mutex.lock();
+ mutex.unlock();
+ thread_group.join_all();
+ if (not called) throw std::runtime_error("test_thread_priority_thread never executed");
+ return result;
+}
diff --git a/tests/thread_pool_test.py b/tests/thread_pool_test.py
index 2c9dcad..0f8b513 100644
--- a/tests/thread_pool_test.py
+++ b/tests/thread_pool_test.py
@@ -19,5 +19,9 @@ class ThreadPoolTest(unittest.TestCase):
tp = gras.ThreadPool(c)
tp.set_active()
+ def test_thread_priority(self):
+ #here we assume prio 0.0 (default) can always be set
+ self.assertTrue(gras.ThreadPool.test_thread_priority(0.0))
+
if __name__ == '__main__':
unittest.main()