commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r5191 - in gnuradio/branches/developers/jcorgan/disc/g


From: jcorgan
Subject: [Commit-gnuradio] r5191 - in gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src: lib/runtime python/gnuradio/gr
Date: Sun, 29 Apr 2007 22:30:28 -0600 (MDT)

Author: jcorgan
Date: 2007-04-29 22:30:28 -0600 (Sun, 29 Apr 2007)
New Revision: 5191

Modified:
   
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime.cc
   
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
   
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
   
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
   
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
Log:
Work in progress, refactored SIGINT handling, added instrumentation.

Modified: 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime.cc
       2007-04-29 16:07:36 UTC (rev 5190)
+++ 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime.cc
       2007-04-30 04:30:28 UTC (rev 5191)
@@ -26,11 +26,8 @@
 
 #include <gr_runtime.h>
 #include <gr_runtime_impl.h>
-#include <gr_local_sighandler.h>
 #include <iostream>
 
-static gr_runtime *s_runtime = 0;
-
 gr_runtime_sptr 
 gr_make_runtime(gr_hier_block2_sptr top_block)
 {
@@ -40,28 +37,16 @@
 gr_runtime::gr_runtime(gr_hier_block2_sptr top_block)
 {
   d_impl = new gr_runtime_impl(top_block);
-  s_runtime = this;
 }
   
 gr_runtime::~gr_runtime()
 {
-  s_runtime = 0; // we don't own this
   delete d_impl;
 }
 
-// FIXME: This prevents using more than one gr_runtime instance
-static void 
-runtime_sigint_handler(int signum)
-{
-  if (s_runtime)
-    s_runtime->stop();
-}
-
 void 
 gr_runtime::start()
 {
-  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
-
   d_impl->start();
 }
 
@@ -74,24 +59,18 @@
 void 
 gr_runtime::wait()
 {
-  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
-
   d_impl->wait();
 }
 
 void 
 gr_runtime::run()
 {
-  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
-
-  d_impl->start();
-  d_impl->wait();
+  start();
+  wait();
 }
 
 void
 gr_runtime::restart()
 {
-  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
-
   d_impl->restart();
 }

Modified: 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
  2007-04-29 16:07:36 UTC (rev 5190)
+++ 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
  2007-04-30 04:30:28 UTC (rev 5191)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2007 Free Software Foundation, Inc.
  *
  * This file is part of GNU Radio
  *
@@ -24,10 +24,12 @@
 #include "config.h"
 #endif
 
+#include <gr_runtime.h>
 #include <gr_runtime_impl.h>
 #include <gr_simple_flowgraph.h>
 #include <gr_hier_block2.h>
 #include <gr_hier_block2_detail.h>
+#include <gr_local_sighandler.h>
 
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
@@ -36,24 +38,39 @@
 #include <stdexcept>
 #include <iostream>
 
+#define GR_RUNTIME_IMPL_DEBUG 1
+
+static gr_runtime_impl *s_runtime = 0;
+
+// FIXME: This prevents using more than one gr_runtime instance
+void 
+runtime_sigint_handler(int signum)
+{
+  if (s_runtime)
+    s_runtime->stop();
+}
+
 gr_runtime_impl::gr_runtime_impl(gr_hier_block2_sptr top_block) 
   : d_running(false),
     d_top_block(top_block),
     d_sfg(gr_make_simple_flowgraph())
 {
+  s_runtime = this;
 }
 
 gr_runtime_impl::~gr_runtime_impl()
 {
+  s_runtime = 0; // we don't own this
 }
 
 void
 gr_runtime_impl::start()
 {
+  if (GR_RUNTIME_IMPL_DEBUG)
+    std::cout << "start: entered" << std::endl;
+
   if (d_running)
     throw std::runtime_error("already running");
-  else
-    d_running = true;
 
   // Create new simple flow graph by flattening hierarchical block
   d_sfg->d_detail->reset();
@@ -70,24 +87,33 @@
 void
 gr_runtime_impl::start_threads()
 {
+  if (GR_RUNTIME_IMPL_DEBUG)
+    std::cout << "start_threads: entered" << std::endl;
+
   d_graphs = d_sfg->d_detail->partition();
-  d_threads.clear();
   for (std::vector<gr_block_vector_t>::iterator p = d_graphs.begin();
        p != d_graphs.end(); p++) {
     gr_scheduler_thread *thread = new gr_scheduler_thread(*p);
+    d_threads.push_back(thread);
+    if (GR_RUNTIME_IMPL_DEBUG)
+      std::cout << "start_threads: starting " << thread << std::endl;
     thread->start();
-    d_threads.push_back(thread);
   }
+
+  d_running = true;
 }
 
 void
 gr_runtime_impl::stop()
 {
-  if (!d_running)
-    throw std::runtime_error("not running");
+  if (GR_RUNTIME_IMPL_DEBUG)
+    std::cout << "stop: entered" << std::endl;
 
-  for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != 
d_threads.end(); p++)
-    (*p)->stop(); 
+  for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != 
d_threads.end(); p++) {
+    if (GR_RUNTIME_IMPL_DEBUG)
+      std::cout << "stop: stopping thread " << (*p) << std::endl;
+    (*p)->stop();
+  }
 
   d_running = false;
 }
@@ -95,24 +121,37 @@
 void
 gr_runtime_impl::wait()
 {
+  if (GR_RUNTIME_IMPL_DEBUG)
+    std::cout << "wait: entered" << std::endl;
+
   void *dummy_status; // don't ever dereference this
+  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
 
   for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != 
d_threads.end(); p++) {
+    if (GR_RUNTIME_IMPL_DEBUG)
+      std::cout << "wait: joining thread " << (*p) << std::endl;
     (*p)->join(&dummy_status); // pthreads will self-delete, so pointer is now 
dead
     (*p) = 0; // FIXME: switch to stl::list and actually remove from container
   }
+
+  d_threads.clear();
 }
 
 void
 gr_runtime_impl::restart()
 {
+  if (GR_RUNTIME_IMPL_DEBUG)
+    std::cout << "restart: entered" << std::endl;
+
   if (!d_running)
     throw std::runtime_error("not running");
 
   // Stop scheduler threads and wait for completion
   stop();
   wait();
-  
+  if (GR_RUNTIME_IMPL_DEBUG)
+    std::cout << "restart: threads stopped" << std::endl;
+
   // Create new simple flow graph 
   gr_simple_flowgraph_sptr new_sfg = gr_make_simple_flowgraph();
   d_top_block->d_detail->flatten(new_sfg);
@@ -161,3 +200,4 @@
 {
   d_sts->stop();
 }
+

Modified: 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
   2007-04-29 16:07:36 UTC (rev 5190)
+++ 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
   2007-04-30 04:30:28 UTC (rev 5191)
@@ -67,6 +67,7 @@
 {
 private:
   gr_runtime_impl(gr_hier_block2_sptr top_block);
+  friend void runtime_sigint_handler(int signum);
   friend class gr_runtime;
     
   bool                           d_running;

Modified: 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
       2007-04-29 16:07:36 UTC (rev 5190)
+++ 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
       2007-04-30 04:30:28 UTC (rev 5191)
@@ -32,6 +32,8 @@
 #include <iostream>
 #include <stdexcept>
 
+#define GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG 1
+
 gr_edge_sptr
 gr_make_edge(const gr_endpoint &src, const gr_endpoint &dst)
 {
@@ -479,5 +481,9 @@
 void
 gr_simple_flowgraph_detail::merge_connections(gr_simple_flowgraph_sptr sfg)
 {
-    // NOT IMPLEMENTED
+  // For each block used in new flow graph, see if it exists in old flow graph
+  for (gr_basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) {
+    if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG)
+      std::cout << "merge: testing " << (*p) << std::endl;
+  }
 }

Modified: 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
===================================================================
--- 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
    2007-04-29 16:07:36 UTC (rev 5190)
+++ 
gnuradio/branches/developers/jcorgan/disc/gnuradio-core/src/python/gnuradio/gr/qa_hier_block2.py
    2007-04-30 04:30:28 UTC (rev 5191)
@@ -230,5 +230,15 @@
         self.assertRaises(ValueError,
             lambda: hblock.disconnect(nop1, (hblock, 1)))
 
+    def test_023_run(self):
+       hblock = gr.top_block("test_block")
+       data = (1.0, 2.0, 3.0, 4.0)
+       src = gr.vector_source_f(data, False)
+       dst = gr.vector_sink_f()
+       hblock.connect(src, dst)
+       r = gr.runtime(hblock)
+       r.run()
+       self.assertEquals(data, dst.data())
+
 if __name__ == "__main__":
     gr_unittest.main()





reply via email to

[Prev in Thread] Current Thread [Next in Thread]