diff options
Diffstat (limited to 'lib')
-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 7775f53..c806063 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 @@ -43,6 +44,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; |