summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2012-12-20 00:44:26 -0800
committerJosh Blum2012-12-20 00:44:26 -0800
commitb6dd30a39ffcd028c7ac5ab8cd7221b158050097 (patch)
treeb938368dbdd8e0c2fe56e99738b2d7a284e962e5
parent77a8eb46febf39d39b8b195aaffa1d4594e94812 (diff)
downloadsandhi-b6dd30a39ffcd028c7ac5ab8cd7221b158050097.tar.gz
sandhi-b6dd30a39ffcd028c7ac5ab8cd7221b158050097.tar.bz2
sandhi-b6dd30a39ffcd028c7ac5ab8cd7221b158050097.zip
created block cleanup and wait for messages
-rw-r--r--lib/block.cpp19
-rw-r--r--lib/element.cpp3
-rw-r--r--lib/element_impl.hpp1
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;