summaryrefslogtreecommitdiff
path: root/lib/thread_pool.cpp
diff options
context:
space:
mode:
authorJosh Blum2013-05-11 16:20:08 -0700
committerJosh Blum2013-05-11 16:20:08 -0700
commit4e210ade63d800b1a8671999f19019abd3c2ae03 (patch)
treeb23f026eb0ba161ebf8ae59087f5c51031946bec /lib/thread_pool.cpp
parent476e5e7f8c949251436646dfd155cdd4430c37f2 (diff)
downloadsandhi-4e210ade63d800b1a8671999f19019abd3c2ae03.tar.gz
sandhi-4e210ade63d800b1a8671999f19019abd3c2ae03.tar.bz2
sandhi-4e210ade63d800b1a8671999f19019abd3c2ae03.zip
gras: created new test_thread_priority api call
Diffstat (limited to 'lib/thread_pool.cpp')
-rw-r--r--lib/thread_pool.cpp37
1 files changed, 36 insertions, 1 deletions
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;
+}