From 39b7a04a8ddac19fa694abdb963e861dc6adeee2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 9 Jun 2013 14:06:49 -0700 Subject: gras: squashed the actor table from threads work (not used yet, but code is ok for mainline) --- lib/block_actor.cpp | 27 +++++++++++++++++++++++---- 1 file 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 #include #include +#include +#include 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 > ThreadPoolMapPair; +typedef std::map > 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); } -- cgit