commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r6178 - gnuradio/branches/developers/jcorgan/fg/gnurad


From: jcorgan
Subject: [Commit-gnuradio] r6178 - gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime
Date: Sun, 26 Aug 2007 22:25:32 -0600 (MDT)

Author: jcorgan
Date: 2007-08-26 22:25:31 -0600 (Sun, 26 Aug 2007)
New Revision: 6178

Added:
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block_impl.h
Modified:
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/Makefile.am
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
   
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_types.h
Log:
Created C++ version of gr_top_block class, will end up being the new
'runtime' object.  Not wired into anything yet.

Refactored gr_scheduler_thread into separate class.


Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/Makefile.am
   2007-08-26 22:58:29 UTC (rev 6177)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/Makefile.am
   2007-08-27 04:25:31 UTC (rev 6178)
@@ -1,5 +1,5 @@
 #
-# Copyright 2003,2004 Free Software Foundation, Inc.
+# Copyright 2003,2004,2007 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
@@ -50,10 +50,13 @@
        gr_realtime.cc                          \
        gr_runtime.cc                           \
        gr_runtime_impl.cc                      \
+       gr_scheduler_thread.cc                  \
        gr_single_threaded_scheduler.cc         \
        gr_sync_block.cc                        \
        gr_sync_decimator.cc                    \
        gr_sync_interpolator.cc                 \
+       gr_top_block.cc                         \
+       gr_top_block_impl.cc                    \
        gr_tmp_path.cc                          \
        gr_vmcircbuf.cc                         \
        gr_vmcircbuf_mmap_shm_open.cc           \
@@ -94,11 +97,14 @@
        gr_runtime.h                            \
        gr_runtime_impl.h                       \
        gr_runtime_types.h                      \
+       gr_scheduler_thread.h                   \
        gr_select_handler.h                     \
        gr_single_threaded_scheduler.h          \
        gr_sync_block.h                         \
        gr_sync_decimator.h                     \
        gr_sync_interpolator.h                  \
+       gr_top_block.h                          \
+       gr_top_block_impl.h                     \
        gr_timer.h                              \
        gr_tmp_path.h                           \
        gr_types.h                              \

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
     2007-08-26 22:58:29 UTC (rev 6177)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.cc
     2007-08-27 04:25:31 UTC (rev 6178)
@@ -35,7 +35,7 @@
                                         gr_io_signature_sptr input_signature,
                                         gr_io_signature_sptr output_signature)
 {
-    return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, 
output_signature));
+  return gr_hier_block2_sptr(new gr_hier_block2(name, input_signature, 
output_signature));
 }
 
 gr_hier_block2::gr_hier_block2(const std::string &name,
@@ -48,39 +48,45 @@
 
 gr_hier_block2::~gr_hier_block2()
 {
-    delete d_detail;
+  delete d_detail;
 }
 
 void 
 gr_hier_block2::connect(gr_basic_block_sptr src, int src_port, 
                         gr_basic_block_sptr dst, int dst_port)
 {
-    d_detail->connect(src, src_port, dst, dst_port);
+  d_detail->connect(src, src_port, dst, dst_port);
 }
 
 void 
 gr_hier_block2::disconnect(gr_basic_block_sptr src, int src_port, 
                            gr_basic_block_sptr dst, int dst_port)
 {
-    d_detail->disconnect(src, src_port, dst, dst_port);
+  d_detail->disconnect(src, src_port, dst, dst_port);
 }
 
 void
 gr_hier_block2::set_runtime(gr_runtime *runtime)
 {
-    if (GR_HIER_BLOCK2_DEBUG)
-      std::cout << "Setting runtime on " << this << " to " << runtime << 
std::endl;
-    d_detail->set_runtime(runtime);
+  if (GR_HIER_BLOCK2_DEBUG)
+    std::cout << "Setting runtime on " << this << " to " << runtime << 
std::endl;
+  d_detail->set_runtime(runtime);
 }
 
 void
 gr_hier_block2::lock()
 {
-    d_detail->lock();
+  d_detail->lock();
 }
 
 void
 gr_hier_block2::unlock()
 {
-    d_detail->unlock();
+  d_detail->unlock();
 }
+
+void
+gr_hier_block2::flatten(gr_flat_flowgraph_sptr ffg)
+{
+  d_detail->flatten(ffg);
+}

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.h
      2007-08-26 22:58:29 UTC (rev 6177)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_hier_block2.h
      2007-08-27 04:25:31 UTC (rev 6178)
@@ -40,34 +40,36 @@
 class gr_hier_block2 : public gr_basic_block
 {
 private:
-    friend class gr_hier_block2_detail;
-    friend class gr_runtime_impl;
-    friend gr_hier_block2_sptr gr_make_hier_block2(const std::string &name,
-                                                   gr_io_signature_sptr 
input_signature,
-                                                   gr_io_signature_sptr 
output_signature);
-
-    /*!
-     * \brief Private implementation details of gr_hier_block2
-     */
-    gr_hier_block2_detail *d_detail;
-
-    /* Internal use only */
-    void set_runtime(gr_runtime *runtime);
-
+  friend class gr_hier_block2_detail;
+  friend class gr_runtime_impl;
+  friend gr_hier_block2_sptr gr_make_hier_block2(const std::string &name,
+                                                gr_io_signature_sptr 
input_signature,
+                                                gr_io_signature_sptr 
output_signature);
+  
+  /*!
+   * \brief Private implementation details of gr_hier_block2
+   */
+  gr_hier_block2_detail *d_detail;
+  
+  /* Internal use only */
+  void set_runtime(gr_runtime *runtime);
+  
 protected: 
-    gr_hier_block2(const std::string &name,
-                   gr_io_signature_sptr input_signature,
-                   gr_io_signature_sptr output_signature);
-
+  gr_hier_block2(const std::string &name,
+                gr_io_signature_sptr input_signature,
+                gr_io_signature_sptr output_signature);
+  
 public:
-    virtual ~gr_hier_block2();
+  virtual ~gr_hier_block2();
+  
+  void connect(gr_basic_block_sptr src, int src_port, 
+              gr_basic_block_sptr dst, int dst_port);
+  void disconnect(gr_basic_block_sptr src, int src_port,
+                 gr_basic_block_sptr dst, int dst_port);
+  void lock();
+  void unlock();
 
-    void connect(gr_basic_block_sptr src, int src_port, 
-                 gr_basic_block_sptr dst, int dst_port);
-    void disconnect(gr_basic_block_sptr src, int src_port,
-                   gr_basic_block_sptr dst, int dst_port);
-    void lock();
-    void unlock();
+  void flatten(gr_flat_flowgraph_sptr ffg);
 };
 
 #endif /* INCLUDED_GR_HIER_BLOCK2_H */

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
    2007-08-26 22:58:29 UTC (rev 6177)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
    2007-08-27 04:25:31 UTC (rev 6178)
@@ -31,10 +31,6 @@
 #include <gr_hier_block2_detail.h>
 #include <gr_local_sighandler.h>
 
-#ifdef HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-
 #include <stdexcept>
 #include <iostream>
 
@@ -212,42 +208,3 @@
 
   start_threads();
 }
-
-gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) :
-  omni_thread(NULL, PRIORITY_NORMAL),
-  d_sts(gr_make_single_threaded_scheduler(graph))
-{
-}
-
-gr_scheduler_thread::~gr_scheduler_thread()
-{
-}
-
-void gr_scheduler_thread::start()
-{
-  start_undetached();
-}
-
-void *
-gr_scheduler_thread::run_undetached(void *arg)
-{
-  // First code to run in new thread context
-
-  // Mask off SIGINT in this thread to gaurantee mainline thread gets signal
-#ifdef HAVE_SIGPROCMASK
-  sigset_t old_set;
-  sigset_t new_set;
-  sigemptyset(&new_set);
-  sigaddset(&new_set, SIGINT);
-  sigprocmask(SIG_BLOCK, &new_set, &old_set);
-#endif
-  // Run the single-threaded scheduler
-  d_sts->run();
-  return 0;
-}
-
-void
-gr_scheduler_thread::stop()
-{
-  d_sts->stop();
-}

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
     2007-08-26 22:58:29 UTC (rev 6177)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
     2007-08-27 04:25:31 UTC (rev 6178)
@@ -25,38 +25,9 @@
 
 #include <gr_runtime_types.h>
 #include <gr_block.h>
-#include <omnithread.h>
-#include <gr_single_threaded_scheduler.h>
+#include <gr_scheduler_thread.h>
 
-// omnithread calls delete on itself after thread exits, so can't use shared 
ptr
-class gr_scheduler_thread;
-typedef std::vector<gr_scheduler_thread *> gr_scheduler_thread_vector_t;
-typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t;
-
 /*!
- *\brief A single thread of execution for the scheduler
- *
- * This class implements a single thread that runs undetached, and
- * invokes the single-threaded block scheduler.  The runtime makes
- * one of these for each distinct partition of a flowgraph and runs
- * them in parallel.
- *
- */
-class gr_scheduler_thread : public omni_thread
-{
-private:
-  gr_single_threaded_scheduler_sptr d_sts;    
-
-public:
-  gr_scheduler_thread(gr_block_vector_t graph);
-  ~gr_scheduler_thread();
-
-  virtual void *run_undetached(void *arg);
-  void start();
-  void stop();
-};
-
-/*!
  *\brief Implementation details of gr_runtime
  *
  * The actual implementation of gr_runtime. Separate class allows

Modified: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_types.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_types.h
    2007-08-26 22:58:29 UTC (rev 6177)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_runtime_types.h
    2007-08-27 04:25:31 UTC (rev 6178)
@@ -39,6 +39,8 @@
 class gr_flowgraph;
 class gr_flat_flowgraph;
 class gr_runtime;
+class gr_top_block;
+class gr_top_block_detail;
 
 typedef boost::shared_ptr<gr_basic_block>       gr_basic_block_sptr;
 typedef boost::shared_ptr<gr_block>             gr_block_sptr;
@@ -50,5 +52,6 @@
 typedef boost::shared_ptr<gr_runtime>          gr_runtime_sptr;
 typedef boost::shared_ptr<gr_flowgraph>         gr_flowgraph_sptr;
 typedef boost::shared_ptr<gr_flat_flowgraph>    gr_flat_flowgraph_sptr;
+typedef boost::shared_ptr<gr_top_block>         gr_top_block_sptr;
 
 #endif /* INCLUDED_GR_RUNTIME_TYPES_H */

Added: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc
                                (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_scheduler_thread.cc
        2007-08-27 04:25:31 UTC (rev 6178)
@@ -0,0 +1,70 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_scheduler_thread.h>
+
+#ifdef HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+
+gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) :
+  omni_thread(NULL, PRIORITY_NORMAL),
+  d_sts(gr_make_single_threaded_scheduler(graph))
+{
+}
+
+gr_scheduler_thread::~gr_scheduler_thread()
+{
+}
+
+void gr_scheduler_thread::start()
+{
+  start_undetached();
+}
+
+void *
+gr_scheduler_thread::run_undetached(void *arg)
+{
+  // First code to run in new thread context
+
+  // Mask off SIGINT in this thread to gaurantee mainline thread gets signal
+#ifdef HAVE_SIGPROCMASK
+  sigset_t old_set;
+  sigset_t new_set;
+  sigemptyset(&new_set);
+  sigaddset(&new_set, SIGINT);
+  sigprocmask(SIG_BLOCK, &new_set, &old_set);
+#endif
+  // Run the single-threaded scheduler
+  d_sts->run();
+  return 0;
+}
+
+void
+gr_scheduler_thread::stop()
+{
+  d_sts->stop();
+}

Added: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h
                         (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_scheduler_thread.h
 2007-08-27 04:25:31 UTC (rev 6178)
@@ -0,0 +1,58 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_SCHEDULER_THREAD_H
+#define INCLUDED_GR_SCHEDULER_THREAD_H
+
+#include <omnithread.h>
+#include <gr_single_threaded_scheduler.h>
+#include <gr_block.h>
+
+// omnithread calls delete on itself after thread exits, so can't use shared 
ptr
+class gr_scheduler_thread;
+typedef std::vector<gr_scheduler_thread *> gr_scheduler_thread_vector_t;
+typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t;
+
+/*!
+ *\brief A single thread of execution for the scheduler
+ *
+ * This class implements a single thread that runs undetached, and
+ * invokes the single-threaded block scheduler.  The runtime makes
+ * one of these for each distinct partition of a flowgraph and runs
+ * them in parallel.
+ *
+ */
+class gr_scheduler_thread : public omni_thread
+{
+private:
+  gr_single_threaded_scheduler_sptr d_sts;    
+
+public:
+  gr_scheduler_thread(gr_block_vector_t graph);
+  ~gr_scheduler_thread();
+
+  virtual void *run_undetached(void *arg);
+  void start();
+  void stop();
+};
+
+#endif /* INCLUDED_GR_SCHEDULER_THREAD_H */

Added: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.cc
                               (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.cc
       2007-08-27 04:25:31 UTC (rev 6178)
@@ -0,0 +1,87 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_top_block.h>
+#include <gr_top_block_impl.h>
+#include <gr_io_signature.h>
+#include <iostream>
+
+gr_top_block_sptr 
+gr_make_top_block(const std::string &name)
+{
+  return gr_top_block_sptr(new gr_top_block(name));
+}
+
+gr_top_block::gr_top_block(const std::string &name)
+  : gr_hier_block2(name, 
+                  gr_make_io_signature(0,0,0), 
+                  gr_make_io_signature(0,0,0))
+  
+{
+  d_impl = new gr_top_block_impl(this);
+}
+  
+gr_top_block::~gr_top_block()
+{
+  delete d_impl;
+}
+
+void 
+gr_top_block::start()
+{
+  d_impl->start();
+}
+
+void 
+gr_top_block::stop()
+{
+  d_impl->stop();
+}
+
+void 
+gr_top_block::wait()
+{
+  d_impl->wait();
+}
+
+void 
+gr_top_block::run()
+{
+  start();
+  wait();
+}
+
+void
+gr_top_block::lock()
+{
+  d_impl->lock();
+}
+
+void
+gr_top_block::unlock()
+{
+  d_impl->unlock();
+}

Added: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.h
                                (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block.h
        2007-08-27 04:25:31 UTC (rev 6178)
@@ -0,0 +1,93 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_TOP_BLOCK_H
+#define INCLUDED_GR_TOP_BLOCK_H
+
+#include <gr_hier_block2.h>
+
+class gr_top_block_impl;
+
+gr_top_block_sptr gr_make_top_block(const std::string &name);
+
+/*!
+ *\brief Top-level hierarchical block representing a flowgraph
+ *
+ */
+class gr_top_block : public gr_hier_block2
+{
+private:
+  gr_top_block(const std::string &name);
+  friend gr_top_block_sptr gr_make_top_block(const std::string &name);
+
+  gr_top_block_impl *d_impl;
+    
+public:
+  ~gr_top_block();
+
+  /*!
+   * Start the enclosed flowgraph.  Creates an undetached scheduler thread for
+   * each flow graph partition. Returns to caller once created.
+   */
+  void start();
+  
+  /*!
+   * Stop the running flowgraph.  Tells each created scheduler thread
+   * to exit, then returns to caller.
+   */
+  void stop();
+
+  /*!
+   * Wait for a stopped flowgraph to complete.  Joins each completed
+   * thread.
+   */
+  void wait();
+
+  /*!
+   * Calls start(), then wait().  Used to run a flowgraph that will stop
+   * on its own, or to run a flowgraph indefinitely until SIGKILL is
+   * received().
+   */
+  void run();
+
+  /*!
+   * Lock a flowgraph in preparation for reconfiguration.  When an equal
+   * number of calls to lock() and unlock() have occurred, the flowgraph
+   * will be restarted automatically.
+   *
+   * N.B. lock() and unlock() cannot be called from a flowgraph thread or
+   * deadlock will occur when reconfiguration happens.
+   */
+  void lock();
+
+  /*!
+   * Lock a flowgraph in preparation for reconfiguration.  When an equal
+   * number of calls to lock() and unlock() have occurred, the flowgraph
+   * will be restarted automatically.
+   *
+   * N.B. lock() and unlock() cannot be called from a flowgraph thread or
+   * deadlock will occur when reconfiguration happens.
+   */
+  void unlock();
+};
+
+#endif /* INCLUDED_GR_TOP_BLOCK_H */

Added: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
                          (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block_impl.cc
  2007-08-27 04:25:31 UTC (rev 6178)
@@ -0,0 +1,209 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_top_block.h>
+#include <gr_top_block_impl.h>
+#include <gr_flat_flowgraph.h>
+#include <gr_scheduler_thread.h>
+#include <gr_local_sighandler.h>
+
+#include <stdexcept>
+#include <iostream>
+
+#define GR_TOP_BLOCK_IMPL_DEBUG 1
+
+static gr_top_block_impl *s_impl = 0;
+
+// Make a vector of gr_block from a vector of gr_basic_block
+static
+gr_block_vector_t
+make_gr_block_vector(gr_basic_block_vector_t &blocks)
+{
+  gr_block_vector_t result;
+  for (gr_basic_block_viter_t p = blocks.begin(); p != blocks.end(); p++) {
+    result.push_back(make_gr_block_sptr(*p));
+  }
+
+  return result;
+}
+
+// FIXME: This prevents using more than one gr_top_block instance
+static void 
+runtime_sigint_handler(int signum)
+{
+  if (GR_TOP_BLOCK_IMPL_DEBUG)
+    std::cout << "SIGINT received, calling stop()" << std::endl;
+
+  if (s_impl)
+    s_impl->stop();
+}
+
+gr_top_block_impl::gr_top_block_impl(gr_top_block *owner) 
+  : d_running(false),
+    d_ffg(gr_make_flat_flowgraph()),
+    d_owner(owner)
+{
+  s_impl = this;
+}
+
+gr_top_block_impl::~gr_top_block_impl()
+{
+  s_impl = 0; // don't call delete we don't own these
+  d_owner = 0;
+}
+
+void
+gr_top_block_impl::start()
+{
+  if (GR_TOP_BLOCK_IMPL_DEBUG)
+    std::cout << "start: entered" << std::endl;
+
+  if (d_running)
+    throw std::runtime_error("already running");
+
+  // Create new flat flow graph by flattening hierarchy
+  d_ffg->clear();
+  d_owner->flatten(d_ffg);
+
+  // Validate new simple flow graph and wire it up
+  d_ffg->validate();
+  d_ffg->setup_connections();
+
+  // Execute scheduler threads
+  start_threads();
+}
+
+void
+gr_top_block_impl::start_threads()
+{
+  if (GR_TOP_BLOCK_IMPL_DEBUG)
+    std::cout << "start_threads: entered" << std::endl;
+
+  d_graphs = d_ffg->partition();
+  for (std::vector<gr_basic_block_vector_t>::iterator p = d_graphs.begin();
+       p != d_graphs.end(); p++) {
+    gr_scheduler_thread *thread = new 
gr_scheduler_thread(make_gr_block_vector(*p));
+    d_threads.push_back(thread);
+    if (GR_TOP_BLOCK_IMPL_DEBUG)
+      std::cout << "start_threads: starting " << thread << std::endl;
+    thread->start();
+  }
+
+  d_running = true;
+}
+
+void
+gr_top_block_impl::stop()
+{
+  if (GR_TOP_BLOCK_IMPL_DEBUG)
+    std::cout << "stop: entered" << std::endl;
+
+  for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != 
d_threads.end(); p++) {
+    if (GR_TOP_BLOCK_IMPL_DEBUG)
+      std::cout << "stop: stopping thread " << (*p) << std::endl;
+    (*p)->stop();
+  }
+
+  d_running = false;
+}
+
+void
+gr_top_block_impl::wait()
+{
+  if (GR_TOP_BLOCK_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_TOP_BLOCK_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
+    if (GR_TOP_BLOCK_IMPL_DEBUG)
+      std::cout << "wait: join returned" << std::endl;
+  }
+
+  d_threads.clear();
+}
+
+// N.B. lock() and unlock() cannot be called from a flow graph thread or
+// deadlock will occur when reconfiguration happens
+void
+gr_top_block_impl::lock()
+{
+  omni_mutex_lock lock(d_reconf);
+  d_lock_count++;
+  if (GR_TOP_BLOCK_IMPL_DEBUG)
+    std::cout << "runtime: locked, count = " << d_lock_count <<  std::endl;
+}
+
+void
+gr_top_block_impl::unlock()
+{
+  omni_mutex_lock lock(d_reconf);
+  if (d_lock_count == 0)
+    throw std::runtime_error("unpaired unlock() call");
+
+  d_lock_count--;
+  if (GR_TOP_BLOCK_IMPL_DEBUG)
+    std::cout << "unlock: unlocked, count = " << d_lock_count << std::endl;
+
+  if (d_lock_count == 0) {
+    if (GR_TOP_BLOCK_IMPL_DEBUG)
+      std::cout << "unlock: restarting flowgraph" << std::endl;
+    restart();
+  }
+}
+
+void
+gr_top_block_impl::restart()
+{
+  if (GR_TOP_BLOCK_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_TOP_BLOCK_IMPL_DEBUG)
+    std::cout << "restart: threads stopped" << std::endl;
+
+  // Create new simple flow graph 
+  gr_flat_flowgraph_sptr new_ffg = gr_make_flat_flowgraph();
+  d_owner->flatten(new_ffg);
+  new_ffg->validate();
+  new_ffg->merge_connections(d_ffg);
+
+  if (GR_TOP_BLOCK_IMPL_DEBUG)
+    std::cout << "restart: replacing old flow graph with new" << std::endl;
+  d_ffg = new_ffg;
+
+  start_threads();
+}

Added: 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block_impl.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block_impl.h
                           (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/fg/gnuradio-core/src/lib/runtime/gr_top_block_impl.h
   2007-08-27 04:25:31 UTC (rev 6178)
@@ -0,0 +1,76 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_TOP_BLOCK_IMPL_H
+#define INCLUDED_GR_TOP_BLOCK_IMPL_H
+
+//#include <gr_runtime_types.h>
+//#include <gr_block.h>
+#include <gr_scheduler_thread.h>
+
+/*!
+ *\brief Implementation details of gr_top_block
+ *
+ * The actual implementation of gr_top_block. Separate class allows
+ * decoupling of changes from dependent classes.
+ *
+ */
+class gr_top_block_impl
+{
+public:
+  gr_top_block_impl(gr_top_block *owner);
+  ~gr_top_block_impl();
+
+  // Create and start scheduler threads
+  void start();
+
+  // Signal scheduler threads to stop
+  void stop();
+
+  // Wait for scheduler threads to exit
+  void wait();
+
+  // Lock the top block to allow reconfiguration
+  void lock();
+
+  // Unlock the top block at end of reconfiguration
+  void unlock();
+
+private:
+    
+  bool                           d_running;
+  gr_flat_flowgraph_sptr         d_ffg;
+  gr_scheduler_thread_vector_t   d_threads;
+  gr_top_block                  *d_owner;
+  int                            d_lock_count;
+  omni_mutex                     d_reconf;
+
+  std::vector<gr_basic_block_vector_t> d_graphs;
+
+  void start_threads();
+  void restart();
+
+public:
+
+};
+
+#endif /* INCLUDED_GR_TOP_BLOCK_IMPL_H */





reply via email to

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