diff options
m--------- | gnuradio | 0 | ||||
-rw-r--r-- | include/gras/thread_pool.hpp | 6 | ||||
-rw-r--r-- | lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/block_actor.cpp | 46 | ||||
-rw-r--r-- | lib/thread_pool.cpp | 57 |
5 files changed, 64 insertions, 46 deletions
diff --git a/gnuradio b/gnuradio -Subproject 14502c92752098e773187890b89db8c763a1ecd +Subproject 89ef118890bcd5df8441be95dfe70a90f39d3bd diff --git a/include/gras/thread_pool.hpp b/include/gras/thread_pool.hpp index abb4d99..e62da3a 100644 --- a/include/gras/thread_pool.hpp +++ b/include/gras/thread_pool.hpp @@ -54,6 +54,12 @@ struct GRAS_API ThreadPoolConfig * Default is BLOCKING. */ std::string yield_strategy; + + /*! + * Relative scheduling priority of the worker threads (range -1.0f to 1.0f, 0.0f is "normal"). + * Default is 0.0f + */ + float thread_priority; }; /*! diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7404bc5..f23d6ea 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -52,6 +52,7 @@ list(APPEND GRAS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/block_consume.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_produce.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_props.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/thread_pool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/block_actor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/task_done.cpp ${CMAKE_CURRENT_SOURCE_DIR}/task_fail.cpp diff --git a/lib/block_actor.cpp b/lib/block_actor.cpp index 5365724..3ce7742 100644 --- a/lib/block_actor.cpp +++ b/lib/block_actor.cpp @@ -2,57 +2,11 @@ #include <gras/thread_pool.hpp> #include <gras_impl/block_actor.hpp> -#include <boost/thread/thread.hpp> #include <Theron/Framework.h> #include <stdexcept> using namespace gras; -ThreadPoolConfig::ThreadPoolConfig(void) -{ - thread_count = boost::thread::hardware_concurrency(); - thread_count = std::max(size_t(2), thread_count); - node_mask = 0; - processor_mask = 0xffffffff; - yield_strategy = "BLOCKING"; - - //environment variable override - const char * gras_yield = getenv("GRAS_YIELD"); - if (gras_yield != NULL) yield_strategy = gras_yield; -} - -/*********************************************************************** - * Thread pool implementation - **********************************************************************/ -ThreadPool::ThreadPool(void) -{ - //NOP -} - -ThreadPool::ThreadPool(boost::weak_ptr<Theron::Framework> p): - boost::shared_ptr<Theron::Framework>(p.lock()) -{ - //NOP -} - -ThreadPool::ThreadPool(const ThreadPoolConfig &config) -{ - Theron::Framework::Parameters params( - config.thread_count, - config.node_mask, - config.processor_mask - ); - - if (config.yield_strategy.empty()) params.mYieldStrategy = Theron::YIELD_STRATEGY_STRONG; - else if (config.yield_strategy == "BLOCKING") params.mYieldStrategy = Theron::YIELD_STRATEGY_BLOCKING; - else if (config.yield_strategy == "POLITE") params.mYieldStrategy = Theron::YIELD_STRATEGY_POLITE; - else if (config.yield_strategy == "STRONG") params.mYieldStrategy = Theron::YIELD_STRATEGY_STRONG; - else if (config.yield_strategy == "AGGRESSIVE") params.mYieldStrategy = Theron::YIELD_STRATEGY_AGGRESSIVE; - else throw std::runtime_error("gras::ThreadPoolConfig yield_strategy unknown: " + config.yield_strategy); - - this->reset(new Theron::Framework(Theron::Framework::Parameters(params))); -} - /*********************************************************************** * Active framework implementation **********************************************************************/ diff --git a/lib/thread_pool.cpp b/lib/thread_pool.cpp new file mode 100644 index 0000000..cd5c320 --- /dev/null +++ b/lib/thread_pool.cpp @@ -0,0 +1,57 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +#include <gras/thread_pool.hpp> +#include <boost/thread/thread.hpp> +#include <Theron/EndPoint.h> +#include <Theron/Framework.h> +#include <stdexcept> + +using namespace gras; + +ThreadPoolConfig::ThreadPoolConfig(void) +{ + thread_count = boost::thread::hardware_concurrency(); + thread_count = std::max(size_t(2), thread_count); + node_mask = 0; + processor_mask = 0xffffffff; + yield_strategy = "BLOCKING"; + thread_priority = 0.0f; + + //environment variable override + const char * gras_yield = getenv("GRAS_YIELD"); + if (gras_yield != NULL) yield_strategy = gras_yield; +} + +/*********************************************************************** + * Thread pool implementation + **********************************************************************/ +ThreadPool::ThreadPool(void) +{ + //NOP +} + +ThreadPool::ThreadPool(boost::weak_ptr<Theron::Framework> p): + boost::shared_ptr<Theron::Framework>(p.lock()) +{ + //NOP +} + +ThreadPool::ThreadPool(const ThreadPoolConfig &config) +{ + Theron::Framework::Parameters params( + config.thread_count, + config.node_mask, + config.processor_mask + ); + + if (config.yield_strategy.empty()) params.mYieldStrategy = Theron::YIELD_STRATEGY_STRONG; + else if (config.yield_strategy == "BLOCKING") params.mYieldStrategy = Theron::YIELD_STRATEGY_BLOCKING; + else if (config.yield_strategy == "POLITE") params.mYieldStrategy = Theron::YIELD_STRATEGY_POLITE; + else if (config.yield_strategy == "STRONG") params.mYieldStrategy = Theron::YIELD_STRATEGY_STRONG; + else if (config.yield_strategy == "AGGRESSIVE") params.mYieldStrategy = Theron::YIELD_STRATEGY_AGGRESSIVE; + else throw std::runtime_error("gras::ThreadPoolConfig yield_strategy unknown: " + config.yield_strategy); + + params.mThreadPriority = config.thread_priority; + + this->reset(new Theron::Framework(Theron::Framework::Parameters(params))); +} |