From 4e210ade63d800b1a8671999f19019abd3c2ae03 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 11 May 2013 16:20:08 -0700 Subject: gras: created new test_thread_priority api call --- lib/thread_pool.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'lib/thread_pool.cpp') 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 -#include +#include //mutex, thread, hardware_concurrency #include #include +#include //prio test #include +#include 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; +} -- cgit