summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2012-09-11 20:33:58 -0700
committerJosh Blum2012-09-11 20:33:58 -0700
commita822c2f3063030d9af172c4d3798885f3281d44e (patch)
treebe2687bd3812b159031ff9a7b115b612c8f36bdd
parent42682f091b9c80b54c3b95b27bb496acc46ce294 (diff)
downloadsandhi-a822c2f3063030d9af172c4d3798885f3281d44e.tar.gz
sandhi-a822c2f3063030d9af172c4d3798885f3281d44e.tar.bz2
sandhi-a822c2f3063030d9af172c4d3798885f3281d44e.zip
added wait w/ timeout to top block/executor
-rw-r--r--TODO.txt1
-rw-r--r--include/gnuradio/top_block.hpp16
-rw-r--r--lib/top_block.cpp14
-rw-r--r--swig/gras.i (renamed from swig/sw_runtime.i)10
-rw-r--r--swig/runtime.i2
5 files changed, 40 insertions, 3 deletions
diff --git a/TODO.txt b/TODO.txt
index 546c1c3..498ca77 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -23,4 +23,3 @@
** thread affinity
** memory affinity
* track memcpys for block usage stats
-* timeout for wait() on executor
diff --git a/include/gnuradio/top_block.hpp b/include/gnuradio/top_block.hpp
index 1a4b4b2..a0a057f 100644
--- a/include/gnuradio/top_block.hpp
+++ b/include/gnuradio/top_block.hpp
@@ -67,8 +67,22 @@ struct GRAS_API TopBlock : HierBlock
//! Stop a flow graph execution (does not block)
void stop(void);
- //! Wait for threads to exit after stop()
+ /*!
+ * Wait for threads to exit after stop() or run().
+ * This is a blocking call and will not return until
+ * all blocks in the topology have been marked done.
+ */
virtual void wait(void);
+
+ /*!
+ * Wait for threads to exit after stop() or run().
+ * This is call will block until timeout or done.
+ *
+ * \param timeout the timeout in seconds
+ * \return true of execution completed
+ */
+ virtual bool wait(const double timeout);
+
};
} //namespace gnuradio
diff --git a/lib/top_block.cpp b/lib/top_block.cpp
index 306e152..f3e1fc8 100644
--- a/lib/top_block.cpp
+++ b/lib/top_block.cpp
@@ -118,3 +118,17 @@ void TopBlock::wait(void)
boost::this_thread::yield();
}
}
+
+bool TopBlock::wait(const double timeout)
+{
+ const boost::system_time exit_time = boost::get_system_time() +
+ boost::posix_time::microseconds(long(timeout*1e6));
+
+ //wait for all blocks to release the token
+ while (not (*this)->token.unique() or boost::get_system_time() < exit_time)
+ {
+ boost::this_thread::yield();
+ }
+
+ return (*this)->token.unique();
+}
diff --git a/swig/sw_runtime.i b/swig/gras.i
index 5e09222..982ee8b 100644
--- a/swig/sw_runtime.i
+++ b/swig/gras.i
@@ -75,6 +75,16 @@ struct TopBlockPython : TopBlock
TopBlock::wait();
)
}
+
+ bool wait(const double timeout)
+ {
+ bool ret = false;
+ GR_PYTHON_BLOCKING_CODE
+ (
+ ret = TopBlock::wait(timeout);
+ )
+ return ret;
+ }
};
}
diff --git a/swig/runtime.i b/swig/runtime.i
index 1d7d80e..e41f711 100644
--- a/swig/runtime.i
+++ b/swig/runtime.i
@@ -48,7 +48,7 @@
#ifdef SW_RUNTIME
-%include "sw_runtime.i"
+%include "gras.i"
#else