diff options
author | Josh Blum | 2013-06-09 14:06:49 -0700 |
---|---|---|
committer | Josh Blum | 2013-06-09 14:06:49 -0700 |
commit | 39b7a04a8ddac19fa694abdb963e861dc6adeee2 (patch) | |
tree | 7c49b7b938e0482a3adbb8150479e74d125f880a | |
parent | 115e9ed0723807c65decc7e8de7d62eec353dab5 (diff) | |
download | sandhi-39b7a04a8ddac19fa694abdb963e861dc6adeee2.tar.gz sandhi-39b7a04a8ddac19fa694abdb963e861dc6adeee2.tar.bz2 sandhi-39b7a04a8ddac19fa694abdb963e861dc6adeee2.zip |
gras: squashed the actor table from threads work
(not used yet, but code is ok for mainline)
-rw-r--r-- | lib/block_actor.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/block_actor.cpp b/lib/block_actor.cpp index de7946e..20b5f6d 100644 --- a/lib/block_actor.cpp +++ b/lib/block_actor.cpp @@ -4,6 +4,8 @@ #include <gras_impl/block_actor.hpp> #include <Theron/Framework.h> #include <iostream> +#include <set> +#include <map> using namespace gras; @@ -17,12 +19,20 @@ void ThreadPool::set_active(void) weak_framework = *this; } -//! this routine used by the query interface only for stats -ThreadPool get_active_thread_pool(void) +/*********************************************************************** + * Map of thread pools to actors - not used externally yet + **********************************************************************/ +typedef std::pair<ThreadPool, std::set<BlockActor *> > ThreadPoolMapPair; +typedef std::map<ThreadPool, std::set<BlockActor *> > ThreadPoolMap; + +static ThreadPoolMap &get_tpm(void) { - return ThreadPool(weak_framework); + static ThreadPoolMap tpm; + return tpm; } +static boost::mutex tpm_mutex; + /*********************************************************************** * Block actor factory - gets active framework **********************************************************************/ @@ -59,9 +69,18 @@ BlockActor::BlockActor(const ThreadPool &tp): this->thread_pool = tp; this->register_handlers(); this->prio_token = Token::make(); + + //enter the actor into the thread pool map + boost::mutex::scoped_lock lock(tpm_mutex); + get_tpm()[tp].insert(this); } BlockActor::~BlockActor(void) { - //NOP + const ThreadPool &tp = this->thread_pool; + + //clear the actor from the thread pool map + boost::mutex::scoped_lock lock(tpm_mutex); + get_tpm()[tp].erase(this); + if (get_tpm()[tp].empty()) get_tpm().erase(tp); } |