Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_single_threaded_scheduler.cc
index 6aaaf954bca9c74a8f699e612a0809b759ed6856..7f1b40641ed7dc3b2bdea505bd1d80edfc467451 100644 (file)
@@ -28,6 +28,7 @@
 #include <gr_block.h>
 #include <gr_block_detail.h>
 #include <gr_buffer.h>
+#include <boost/thread.hpp>
 #include <iostream>
 #include <limits>
 #include <assert.h>
 
 static int which_scheduler  = 0;
 
-
-std::ostream&
-operator << (std::ostream& os, const gr_block *m)
-{
-  os << "<gr_block " << m->name() << " (" << m->unique_id() << ")>";
-  return os;
-}
-
 gr_single_threaded_scheduler_sptr
 gr_make_single_threaded_scheduler (const std::vector<gr_block_sptr> &blocks)
 {
@@ -82,10 +75,18 @@ gr_single_threaded_scheduler::~gr_single_threaded_scheduler ()
 void
 gr_single_threaded_scheduler::run ()
 {
-  d_enabled = true;
+  // d_enabled = true;         // KLUDGE
   main_loop ();
 }
 
+void
+gr_single_threaded_scheduler::stop ()
+{ 
+  if (0)
+    std::cout << "gr_singled_threaded_scheduler::stop() "
+             << this << std::endl;
+  d_enabled = false;
+}
 
 inline static unsigned int
 round_up (unsigned int n, unsigned int multiple)
@@ -154,6 +155,9 @@ gr_single_threaded_scheduler::main_loop ()
   nalive = d_blocks.size ();
   while (d_enabled && nalive > 0){
 
+    if (boost::this_thread::interruption_requested())
+      break;
+
     gr_block           *m = d_blocks[bi].get ();
     gr_block_detail    *d = m->detail().get ();