diff options
author | Josh Blum | 2013-04-14 18:52:50 -0700 |
---|---|---|
committer | Josh Blum | 2013-04-14 18:52:50 -0700 |
commit | f5160d46958586c126a45d2b6a11b6f409c1998b (patch) | |
tree | 7a25157355b78173ac518bc538886688bcd1d736 /lib/block.cpp | |
parent | 445a71cd46511914c4fc7468e784495b7354a02f (diff) | |
download | sandhi-f5160d46958586c126a45d2b6a11b6f409c1998b.tar.gz sandhi-f5160d46958586c126a45d2b6a11b6f409c1998b.tar.bz2 sandhi-f5160d46958586c126a45d2b6a11b6f409c1998b.zip |
gras: warning prints for block implementations that hang
Diffstat (limited to 'lib/block.cpp')
-rw-r--r-- | lib/block.cpp | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/lib/block.cpp b/lib/block.cpp index 2506cc8..82c0535 100644 --- a/lib/block.cpp +++ b/lib/block.cpp @@ -2,7 +2,8 @@ #include "element_impl.hpp" #include <gras/block.hpp> -#include <boost/thread/thread.hpp> //yield +#include <boost/thread/thread.hpp> //sleep +#include <iostream> using namespace gras; @@ -51,14 +52,56 @@ Block::~Block(void) //NOP } -void ElementImpl::block_cleanup(void) +enum block_cleanup_state_type { - //wait for actor to chew through enqueued messages - while (this->block->GetNumQueuedMessages()) + BLOCK_CLEANUP_WAIT, + BLOCK_CLEANUP_WARN, + BLOCK_CLEANUP_DAMN, + BLOCK_CLEANUP_DOTS, +}; + +static void wait_block_cleanup(ElementImpl &self) +{ + const boost::system_time start = boost::get_system_time(); + block_cleanup_state_type state = BLOCK_CLEANUP_WAIT; + while (self.block->GetNumQueuedMessages()) { - //TODO timeout if this does not stop - boost::this_thread::yield(); + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + switch (state) + { + case BLOCK_CLEANUP_WAIT: + if (boost::get_system_time() > start + boost::posix_time::seconds(1)) + { + std::cerr << self.id << ", waiting for you to finish." << std::endl; + state = BLOCK_CLEANUP_WARN; + } + break; + + case BLOCK_CLEANUP_WARN: + if (boost::get_system_time() > start + boost::posix_time::seconds(2)) + { + std::cerr << self.id << ", give up the thread context!" << std::endl; + state = BLOCK_CLEANUP_DAMN; + } + break; + + case BLOCK_CLEANUP_DAMN: + if (boost::get_system_time() > start + boost::posix_time::seconds(3)) + { + std::cerr << self.id << " FAIL; application will now hang..." << std::endl; + state = BLOCK_CLEANUP_DOTS; + } + break; + + case BLOCK_CLEANUP_DOTS: break; + } } +} + +void ElementImpl::block_cleanup(void) +{ + //wait for actor to chew through enqueued messages + wait_block_cleanup(*this); //delete the actor this->block.reset(); |