commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4908 - gnuradio/branches/developers/eb/ibu/mblock/src


From: eb
Subject: [Commit-gnuradio] r4908 - gnuradio/branches/developers/eb/ibu/mblock/src/lib
Date: Fri, 6 Apr 2007 21:02:36 -0600 (MDT)

Author: eb
Date: 2007-04-06 21:02:35 -0600 (Fri, 06 Apr 2007)
New Revision: 4908

Added:
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.h
Modified:
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.h
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.cc
   gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.h
   
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.cc
   
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.h
Log:
work-in-progress on mblocks

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am      
2007-04-07 01:49:33 UTC (rev 4907)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am      
2007-04-07 03:02:35 UTC (rev 4908)
@@ -49,7 +49,8 @@
        mb_runtime.cc                   \
        mb_runtime_nop.cc               \
        mb_runtime_thread_per_mblock.cc \
-       mb_util.cc                      
+       mb_util.cc                      \
+       mb_worker.cc                    
 
 
 # magic flags
@@ -74,7 +75,6 @@
        mb_protocol_class.h             \
        mb_runtime.h                    \
        mb_runtime_nop.h                \
-       mb_runtime_thread_per_mblock.h  \
        mb_util.h                       
 
 
@@ -83,6 +83,8 @@
        mb_endpoint.h                   \
        mb_mblock_impl.h                \
        mb_msg_accepter_smp.h           \
+       mb_runtime_thread_per_mblock.h  \
+       mb_worker.h                     \
        mbi_runtime_lock.h              \
        qa_mblock.h                     \
        qa_mblock_prims.h               \

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.cc  
2007-04-07 01:49:33 UTC (rev 4907)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.cc  
2007-04-07 03:02:35 UTC (rev 4908)
@@ -90,3 +90,11 @@
   : mbe_base(mb, "Invalid port type for connection: " + 
mb_util::join_names(comp_name, port_name))
 {
 }
+
+mbe_terminate::mbe_terminate()
+{
+}
+
+mbe_exit::mbe_exit()
+{
+}

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.h   
2007-04-07 01:49:33 UTC (rev 4907)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_exception.h   
2007-04-07 03:02:35 UTC (rev 4908)
@@ -93,6 +93,18 @@
                        const std::string &port_name);
 };
 
+// not derived from mbe_base to simplify try/catch
+class mbe_terminate
+{
+public:
+  mbe_terminate();
+};
 
+// not derived from mbe_base to simplify try/catch
+class mbe_exit
+{
+public:
+  mbe_exit();
+};
 
 #endif /* INCLUDED_MB_EXCEPTION_H */

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc     
2007-04-07 01:49:33 UTC (rev 4907)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.cc     
2007-04-07 03:02:35 UTC (rev 4908)
@@ -153,3 +153,15 @@
 {
   return d_impl->mblock_parent();
 }
+
+void
+mb_mblock::exit()
+{
+  d_impl->exit();
+}
+
+void
+mb_mblock::terminate_all()
+{
+  d_impl->terminate_all();
+}

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h      
2007-04-07 01:49:33 UTC (rev 4907)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock.h      
2007-04-07 03:02:35 UTC (rev 4908)
@@ -186,6 +186,31 @@
   //! Set the class name
   void set_class_name(const std::string &name);
 
+  /*!
+   * \brief Tell runtime that we are done.
+   *
+   * runtime->run(...) returns when all blocks have called exit.
+   */
+  void exit();
+
+  /*!
+   * \brief Ask runtime to start termination procedure for all blocks.
+   * 
+   * The runtime first sends a maximum priority %Terminate message to
+   * all blocks.  All blocks should handle the %Terminate message,
+   * perform whatever clean up is required, and call this->exit();
+   *
+   * After a period of time (~200ms), any blocks which haven't yet
+   * called this->exit() are sent a SIG<FOO> (TBD) signal, which will
+   * blow them out of any blocking system calls and raise a
+   * mbe_terminate exception.  The default top-level runtime-provided
+   * exception handler will call this->exit() to finish the process.
+   *
+   * runtime->run(...) returns when all blocks have called exit.
+   */
+  void terminate_all();
+
+  
 public:
   virtual ~mb_mblock();
 

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.cc        
2007-04-07 01:49:33 UTC (rev 4907)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.cc        
2007-04-07 03:02:35 UTC (rev 4908)
@@ -295,3 +295,14 @@
   d_class_name = name;
 }
 
+void
+mb_mblock_impl::exit()
+{
+  throw mbe_exit();    // adios...
+}
+
+void
+mb_mblock_impl::terminate_all()
+{
+  // FIXME
+}

Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.h 
2007-04-07 01:49:33 UTC (rev 4907)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_mblock_impl.h 
2007-04-07 03:02:35 UTC (rev 4908)
@@ -142,6 +142,30 @@
   int
   nconnections();
 
+  /*!
+   * \brief Tell runtime that we are done.
+   *
+   * runtime->run(...) returns when all blocks have called exit.
+   */
+  void exit();
+
+  /*!
+   * \brief Ask runtime to start termination procedure for all blocks.
+   * 
+   * The runtime first sends a maximum priority %Terminate message to
+   * all blocks.  All blocks should handle the %Terminate message,
+   * perform whatever clean up is required, and call this->exit();
+   *
+   * After a period of time (~200ms), any blocks which haven't yet
+   * called this->exit() are sent a SIG<FOO> (TBD) signal, which will
+   * blow them out of any blocking system calls and raise a
+   * mbe_terminate exception.  The default top-level runtime-provided
+   * exception handler will call this->exit() to finish the process.
+   *
+   * runtime->run(...) returns when all blocks have called exit.
+   */
+  void terminate_all();
+
   bool
   walk_tree(mb_visitor *visitor);
   

Modified: 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.cc
===================================================================
--- 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.cc
  2007-04-07 01:49:33 UTC (rev 4907)
+++ 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.cc
  2007-04-07 03:02:35 UTC (rev 4908)
@@ -33,6 +33,7 @@
 
 
 mb_runtime_thread_per_mblock::mb_runtime_thread_per_mblock()
+  : d_runtime_cond(&d_mutex)
 {
   // nop for now
 }

Modified: 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.h
===================================================================
--- 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.h
   2007-04-07 01:49:33 UTC (rev 4907)
+++ 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_mblock.h
   2007-04-07 03:02:35 UTC (rev 4908)
@@ -25,10 +25,16 @@
 
 /*!
  * \brief Concrete runtime that uses a thread per mblock
+ * \implementation
+ *
+ * This is all implementation details.
  */
 class mb_runtime_thread_per_mblock : public mb_runtime
 {
 public:
+  omni_mutex           d_mutex;
+  omni_condition       d_runtime_cond;   // runtime waits here when it's got 
nothing to do
+
   mb_runtime_thread_per_mblock();
   ~mb_runtime_thread_per_mblock();
 

Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.cc             
                (rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.cc     
2007-04-07 03:02:35 UTC (rev 4908)
@@ -0,0 +1,77 @@
+/* -*- 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 2, 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <mb_worker.h>
+#include <mb_runtime_thread_per_mblock.h>
+#include <mb_exception.h>
+
+
+
+mb_worker::mb_worker(mb_runtime_thread_per_mblock *runtime,
+                    mb_mblock_maker_t maker,
+                    const std::string &instance_name,
+                    pmt_t user_arg)
+  : omni_thread((void *) 0, PRIORITY_NORMAL),
+    d_runtime(runtime), d_maker(maker),
+    d_instance_name(instance_name), d_user_arg(user_arg),
+    d_state_cond(&d_mutex), d_state(TS_UNITIALIZED),
+    d_why_dead(RIP_NOT_DEAD_YET)
+{
+}
+
+mb_worker::~mb_worker()
+{
+}
+
+void *
+mb_worker::run_undetached(void *ignored)
+{
+  try {
+    worker_thread_top_level();
+  }
+  catch (mbe_terminate){
+    d_why_dead = RIP_TERMINATE;
+  }
+  catch (mbe_exit){
+    d_why_dead = RIP_EXIT;
+  }
+  catch (...){
+    if (d_why_dead == RIP_NOT_DEAD_YET)
+      d_why_dead = RIP_UNHANDLED_EXCEPTION;
+  }
+
+  omni_mutex_lock      l1(d_runtime->d_mutex); // lock runtime first, then 
worker
+  omni_mutex_lock      l2(d_mutex);
+
+  d_state = TS_DEAD;                     // update our state
+  d_state_cond.broadcast();              // Notify anybody who cares...
+  d_runtime->d_runtime_cond.broadcast();
+
+  return 0;
+}
+
+void
+mb_worker::worker_thread_top_level()
+{
+}

Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.h              
                (rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_worker.h      
2007-04-07 03:02:35 UTC (rev 4908)
@@ -0,0 +1,100 @@
+/* -*- 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 2, 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_MB_WORKER_H
+#define INCLUDED_MB_WORKER_H
+
+#include <omnithread.h>
+#include <mb_common.h>
+#include <mb_class_registry.h>
+
+
+class mb_runtime_thread_per_mblock;
+
+/*!
+ * \brief Worker thread for thread_per_mblock runtime
+ * \implementation
+ */
+class mb_worker : public omni_thread
+{
+public:
+  //! worker thread states
+  enum worker_state_t {
+    TS_UNITIALIZED,    // new, uninitialized
+    TS_CONSTRUCTED,    // mblock was successfully constructed by thread
+    TS_RUN_INITIAL,    // thread should run initial_transition
+    TS_RUNNING,                // normal steady-state condition.
+    TS_DEAD            // thread is dead
+  };
+
+  //! why we're dead
+  enum cause_of_death_t {
+    RIP_NOT_DEAD_YET,          // not dead
+    RIP_EXIT,                  // normal exit
+    RIP_TERMINATE,             // caught terminate exception
+    RIP_CTOR_EXCEPTION,                // constructor raised an exception
+    RIP_INIT_EXCEPTION,                // initial_transition rasised an 
exception
+    RIP_UNHANDLED_EXCEPTION    // somebody (most likely handle_message) raised 
an exception
+  };
+
+  /*
+   * Args used by new thread to create mb_mblock
+   */
+  mb_runtime_thread_per_mblock *d_runtime;
+  mb_mblock_maker_t            d_maker;
+  std::string                  d_instance_name;
+  pmt_t                                d_user_arg;
+
+  mb_mblock_sptr               d_mblock;       //< holds pointer to created 
mblock
+
+  /*!
+   * \brief General mutex for all these fields.
+   *
+   * They are accessed by both the main runtime thread and the newly
+   * created thread that runs the mblock's main loop.
+   */
+  omni_mutex                   d_mutex; 
+  omni_condition               d_state_cond;   //< state change notifications
+  worker_state_t               d_state;
+  cause_of_death_t             d_why_dead;
+
+  mb_worker(mb_runtime_thread_per_mblock *runtime,
+           mb_mblock_maker_t maker,
+           const std::string &instance_name,
+           pmt_t user_arg);
+
+  ~mb_worker();
+
+
+  /*!
+   * \brief This code runs as the top-level of the new thread
+   */
+  void worker_thread_top_level();
+  
+  /*!
+   * \brief Invokes the top-level of the new thread (name kind of sucks)
+   */
+  void *run_undetached(void *arg);
+};
+
+
+
+#endif /* INCLUDED_MB_WORKER_H */





reply via email to

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