commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4476 - gnuradio/branches/developers/jcorgan/ticket-12


From: jcorgan
Subject: [Commit-gnuradio] r4476 - gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime
Date: Tue, 13 Feb 2007 16:49:10 -0700 (MST)

Author: jcorgan
Date: 2007-02-13 16:49:10 -0700 (Tue, 13 Feb 2007)
New Revision: 4476

Modified:
   
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime.cc
   
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime.h
   
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
   
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
Log:
Work in progress.  Added restart() to gr_runtime (incomplete) and emacsified 
formatting.


Modified: 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime.cc
 2007-02-13 21:35:35 UTC (rev 4475)
+++ 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime.cc
 2007-02-13 23:49:10 UTC (rev 4476)
@@ -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
  * 
@@ -34,56 +34,64 @@
 gr_runtime_sptr 
 gr_make_runtime(gr_hier_block2_sptr top_block)
 {
-    return gr_runtime_sptr(new gr_runtime(top_block));
+  return gr_runtime_sptr(new gr_runtime(top_block));
 }
 
 gr_runtime::gr_runtime(gr_hier_block2_sptr top_block)
 {
-    d_impl = new gr_runtime_impl(top_block);
-    s_runtime = this;
+  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;
+  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();
+  if (s_runtime)
+    s_runtime->stop();
 }
 
 void 
 gr_runtime::start()
 {
-    gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
+  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
 
-    d_impl->start();
+  d_impl->start();
 }
 
 void 
 gr_runtime::stop()
 {
-    d_impl->stop();
+  d_impl->stop();
 }
 
 void 
 gr_runtime::wait()
 {
-    gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
+  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
 
-    d_impl->wait();
+  d_impl->wait();
 }
 
 void 
 gr_runtime::run()
 {
-    gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
+  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
 
-    d_impl->start();
-    d_impl->wait();
+  d_impl->start();
+  d_impl->wait();
 }
+
+void
+gr_runtime::restart()
+{
+  gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
+
+  d_impl->restart();
+}

Modified: 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime.h
  2007-02-13 21:35:35 UTC (rev 4475)
+++ 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime.h
  2007-02-13 23:49:10 UTC (rev 4476)
@@ -40,18 +40,46 @@
 class gr_runtime
 {
 private:
-    gr_runtime(gr_hier_block2_sptr top_block);
-    friend gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block);
+  gr_runtime(gr_hier_block2_sptr top_block);
+  friend gr_runtime_sptr gr_make_runtime(gr_hier_block2_sptr top_block);
 
-    gr_runtime_impl *d_impl;
+  gr_runtime_impl *d_impl;
     
 public:
-    ~gr_runtime();
+  ~gr_runtime();
 
-    void start();
-    void stop();
-    void wait();
-    void run();
+  /*!
+   * Start the flow graph.  Creates an undetached scheduler thread for
+   * each flow graph partition. Returns to caller once created.
+   */
+  void start();
+  
+  /*!
+   * Stop a running flow graph.  Tells each created scheduler thread
+   * to exit, then returns to caller.
+   */
+  void stop();
+
+  /*!
+   * Wait for a stopped flow graph to complete.  Joins each completed
+   * thread.
+   */
+  void wait();
+
+  /*!
+   * Calls start(), then wait().  Used to run a flow graph that will stop
+   * on its own, or to run a flow graph indefinitely until SIGTERM is
+   * received().
+   */
+  void run();
+
+  /*!
+   * Restart a running flow graph, after topology changes have
+   * been made to its top_block (or children). Causes each created 
+   * scheduler thread to end, recalculates the flow graph, and 
+   * recreates new threads (possibly a different number from before.)
+   */
+  void restart();
 };
 
 #endif /* INCLUDED_GR_RUNTIME_H */

Modified: 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
    2007-02-13 21:35:35 UTC (rev 4475)
+++ 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
    2007-02-13 23:49:10 UTC (rev 4476)
@@ -52,56 +52,86 @@
 void
 gr_runtime_impl::start()
 {
-    if (d_running)
-        throw std::runtime_error("already running");
-    else
-        d_running = true;
+  if (d_running)
+    throw std::runtime_error("already running");
+  else
+    d_running = true;
 
-    d_sfg->d_detail->reset();
-    d_top_block->d_detail->flatten(d_sfg);
-    d_sfg->d_detail->validate();
-    d_sfg->d_detail->setup_connections();
+  // Create new simple flow graph by flattening hierarchical block
+  d_sfg->d_detail->reset();
+  d_top_block->d_detail->flatten(d_sfg);
 
-    d_graphs = d_sfg->d_detail->partition();
-    if (GR_RUNTIME_IMPL_DEBUG)
-        std::cout << "Flow graph has " << d_graphs.size()
-                  << " sub-graphs." << std::endl;
+  // Validate new simple flow graph and wire it up
+  d_sfg->d_detail->validate();
+  d_sfg->d_detail->setup_connections();
 
-    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);
-        thread->start();
-        d_threads.push_back(thread);
-    }
+  // Execute scheduler threads
+  start_threads();
 }
 
 void
+gr_runtime_impl::start_threads()
+{
+  d_graphs = d_sfg->d_detail->partition();
+  if (GR_RUNTIME_IMPL_DEBUG)
+    std::cout << "Flow graph has " << d_graphs.size()
+             << " sub-graphs." << std::endl;
+
+  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);
+    thread->start();
+    d_threads.push_back(thread);
+  }
+}
+
+void
 gr_runtime_impl::stop()
 {
-    if (!d_running)
-        throw std::runtime_error("not running");
+  if (!d_running)
+    throw std::runtime_error("not running");
 
-    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++)
+    (*p)->stop(); 
 
-    d_running = false;
+  d_running = false;
 }
 
 void
 gr_runtime_impl::wait()
 {
-    void *dummy_status; // don't ever dereference this
+  void *dummy_status; // don't ever dereference this
 
-    for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != 
d_threads.end(); p++) {
-        (*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
-    }
+  for (gr_scheduler_thread_viter_t p = d_threads.begin(); p != 
d_threads.end(); p++) {
+    (*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
+  }
 }
 
+void
+gr_runtime_impl::restart()
+{
+  if (!d_running)
+    throw std::runtime_error("not running");
+
+  // Stop scheduler threads and wait for completion
+  stop();
+  wait();
+  
+  // Create new simple flow graph 
+  gr_simple_flowgraph_sptr new_sfg = gr_make_simple_flowgraph();
+  d_top_block->d_detail->flatten(new_sfg);
+  new_sfg->validate();
+  // new_sfg->merge_connections(d_sfg)
+  // d_sfg = new_sfg;
+
+  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))
+  omni_thread(NULL, PRIORITY_NORMAL),
+  d_sts(gr_make_single_threaded_scheduler(graph))
 {
 }
 
@@ -111,28 +141,30 @@
 
 void gr_scheduler_thread::start()
 {
-    start_undetached();
+  start_undetached();
 }
 
 void *
 gr_scheduler_thread::run_undetached(void *arg)
 {
-    // First code to run in new thread context
+  // First code to run in new thread context
 
-    // Mask off SIGINT in this thread to gaurantee mainline thread gets signal
+  // 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);
+  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;
+  // Run the single-threaded scheduler
+  d_sts->run();
+  return 0;
 }
 
-void gr_scheduler_thread::stop()
+void
+gr_scheduler_thread::stop()
 {
-    d_sts->stop();
+  d_sts->stop();
 }
+

Modified: 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
     2007-02-13 21:35:35 UTC (rev 4475)
+++ 
gnuradio/branches/developers/jcorgan/ticket-129/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
     2007-02-13 23:49:10 UTC (rev 4476)
@@ -45,15 +45,15 @@
 class gr_scheduler_thread : public omni_thread
 {
 private:
-    gr_single_threaded_scheduler_sptr d_sts;    
+  gr_single_threaded_scheduler_sptr d_sts;    
 
 public:
-    gr_scheduler_thread(gr_block_vector_t graph);
-    ~gr_scheduler_thread();
+  gr_scheduler_thread(gr_block_vector_t graph);
+  ~gr_scheduler_thread();
 
-    virtual void *run_undetached(void *arg);
-    void start();
-    void stop();
+  virtual void *run_undetached(void *arg);
+  void start();
+  void stop();
 };
 
 /*!
@@ -66,21 +66,23 @@
 class gr_runtime_impl
 {
 private:
-    gr_runtime_impl(gr_hier_block2_sptr top_block);
-    friend class gr_runtime;
+  gr_runtime_impl(gr_hier_block2_sptr top_block);
+  friend class gr_runtime;
     
-    bool                           d_running;
-    gr_hier_block2_sptr            d_top_block;
-    gr_simple_flowgraph_sptr       d_sfg;
-    std::vector<gr_block_vector_t> d_graphs;
-    gr_scheduler_thread_vector_t   d_threads;
+  bool                           d_running;
+  gr_hier_block2_sptr            d_top_block;
+  gr_simple_flowgraph_sptr       d_sfg;
+  std::vector<gr_block_vector_t> d_graphs;
+  gr_scheduler_thread_vector_t   d_threads;
             
-    void start();
-    void stop();
-    void wait();
-    
+  void start();
+  void start_threads();
+  void stop();
+  void wait();
+  void restart();
+
 public:
-    ~gr_runtime_impl();
+  ~gr_runtime_impl();
 
 };
 





reply via email to

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