diff options
author | Josh Blum | 2012-12-20 00:44:26 -0800 |
---|---|---|
committer | Josh Blum | 2012-12-20 00:46:30 -0800 |
commit | d894bb05542963774aea5dae78a88ea5fbc595cc (patch) | |
tree | eb39ff46078f4592faa169cab0cac7d9db05d975 | |
parent | 59d8dafe387b11ecf8bfff892e1e30fe07e33caa (diff) | |
download | sandhi-d894bb05542963774aea5dae78a88ea5fbc595cc.tar.gz sandhi-d894bb05542963774aea5dae78a88ea5fbc595cc.tar.bz2 sandhi-d894bb05542963774aea5dae78a88ea5fbc595cc.zip |
created block cleanup and wait for messages
-rw-r--r-- | lib/block.cpp | 19 | ||||
-rw-r--r-- | lib/element.cpp | 3 | ||||
-rw-r--r-- | lib/element_impl.hpp | 1 |
3 files changed, 20 insertions, 3 deletions
diff --git a/lib/block.cpp b/lib/block.cpp index 4f7c7c9..85f7654 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -3,6 +3,7 @@ #include "element_impl.hpp" #include <gras/block.hpp> #include <boost/foreach.hpp> +#include <boost/thread/thread.hpp> //yield using namespace gras; @@ -28,7 +29,7 @@ Block::Block(void) Block::Block(const std::string &name): Element(name) { - (*this)->block = boost::shared_ptr<BlockActor>(new BlockActor()); + (*this)->block.reset(new BlockActor()); (*this)->thread_pool = (*this)->block->thread_pool; //ref copy of pool (*this)->block->name = name; //for debug purposes @@ -44,6 +45,22 @@ Block::Block(const std::string &name): this->set_buffer_affinity(-1); } +void ElementImpl::block_cleanup(void) +{ + //wait for actor to chew through enqueued messages + while (this->block->GetNumQueuedMessages()) + { + //TODO timeout if this does not stop + boost::this_thread::yield(); + } + + //delete the actor + this->block.reset(); + + //unref actor's framework + this->thread_pool.reset(); //must be deleted after actor +} + template <typename V, typename T> void vector_set(V &v, const T &t, const size_t index) { diff --git a/lib/element.cpp b/lib/element.cpp index d623183..27a5db0 100644 --- a/lib/element.cpp +++ b/lib/element.cpp @@ -32,8 +32,7 @@ ElementImpl::~ElementImpl(void) { if (this->executor) this->top_block_cleanup(); if (this->topology) this->hier_block_cleanup(); - this->block.reset(); - this->thread_pool.reset(); //must be deleted after actor + if (this->block) this->block_cleanup(); } Element &Element::shared_to_element(void) diff --git a/lib/element_impl.hpp b/lib/element_impl.hpp index 6376b89..5c2d998 100644 --- a/lib/element_impl.hpp +++ b/lib/element_impl.hpp @@ -21,6 +21,7 @@ struct ElementImpl ~ElementImpl(void); void top_block_cleanup(void); void hier_block_cleanup(void); + void block_cleanup(void); //common element properties std::string name; |