commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4118 - in gnuradio/branches/developers/jcorgan/sfg: g


From: jcorgan
Subject: [Commit-gnuradio] r4118 - in gnuradio/branches/developers/jcorgan/sfg: gnuradio-core/src/lib/runtime gnuradio-examples/c++/dialtone gr-audio-alsa/src
Date: Sun, 17 Dec 2006 17:24:33 -0700 (MST)

Author: jcorgan
Date: 2006-12-17 17:24:33 -0700 (Sun, 17 Dec 2006)
New Revision: 4118

Added:
   
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/test_head.cc
   
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/test_head.h
Modified:
   
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime.cc
   
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
   
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
   
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
   gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/
   
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/Makefile.am
   gnuradio/branches/developers/jcorgan/sfg/gr-audio-alsa/src/audio_alsa_sink.cc
Log:
Work in progress fixing threading bugs.

Modified: 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime.cc
        2006-12-17 23:31:51 UTC (rev 4117)
+++ 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime.cc
        2006-12-18 00:24:33 UTC (rev 4118)
@@ -26,8 +26,12 @@
 
 #include <gr_runtime.h>
 #include <gr_runtime_impl.h>
+#include <gr_local_sighandler.h>
 #include <iostream>
 
+static char *hitmsg = "SIGINT handler hit\n";
+static gr_runtime *s_runtime = 0;
+
 gr_runtime_sptr 
 gr_make_runtime(gr_hier_block2_sptr top_block)
 {
@@ -37,16 +41,29 @@
 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 forces there to be only one runtime instance
+static void 
+runtime_sigint_handler(int signum)
+{
+    write(2, hitmsg, strlen(hitmsg));
+    if (s_runtime)
+        s_runtime->stop();
+}
+
 void 
 gr_runtime::start()
 {
+    gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
+
     d_impl->start();
 }
 
@@ -59,12 +76,16 @@
 void 
 gr_runtime::wait()
 {
+    gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
+
     d_impl->wait();
 }
 
 void 
 gr_runtime::run()
 {
-    start();
-    wait();
+    gr_local_sighandler sigint(SIGINT, runtime_sigint_handler);
+
+    d_impl->start();
+    d_impl->wait();
 }

Modified: 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
   2006-12-17 23:31:51 UTC (rev 4117)
+++ 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime_impl.cc
   2006-12-18 00:24:33 UTC (rev 4118)
@@ -24,20 +24,21 @@
 #include "config.h"
 #endif
 
-#define GR_RUNTIME_IMPL_DEBUG 0
+#define GR_RUNTIME_IMPL_DEBUG 1
 
 #include <gr_runtime_impl.h>
 #include <gr_simple_flowgraph.h>
 #include <gr_hier_block2.h>
 #include <gr_hier_block2_detail.h>
+#include <signal.h>
 #include <stdexcept>
 #include <iostream>
 
-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()),
-d_graphs()
+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()),
+    d_graphs()
 {
 }
 
@@ -66,7 +67,7 @@
     d_threads.clear();
     for (std::vector<gr_block_vector_t>::iterator p = d_graphs.begin();
          p != d_graphs.end(); p++) {
-        gr_scheduler_thread_sptr thread = gr_make_scheduler_thread(*p);
+        gr_scheduler_thread *thread = new gr_scheduler_thread(*p);
         thread->start();
         d_threads.push_back(thread);
     }
@@ -78,9 +79,8 @@
     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;
 }
@@ -88,21 +88,14 @@
 void
 gr_runtime_impl::wait()
 {
-    for (gr_scheduler_thread_viter_t p = d_threads.begin(); 
-         p != d_threads.end(); p++) {
-        while(1) {
-            (*p)->join(NULL);
-            if (!(*p)->state() == omni_thread::STATE_TERMINATED)
-                break;
-        }
+    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
     }
 }
 
-gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph)
-{
-    return gr_scheduler_thread_sptr(new gr_scheduler_thread(graph));
-}
-
 gr_scheduler_thread::gr_scheduler_thread(gr_block_vector_t graph) :
     omni_thread(NULL, PRIORITY_NORMAL),
     d_sts(gr_make_single_threaded_scheduler(graph))
@@ -118,8 +111,19 @@
     start_undetached();
 }
 
-void *gr_scheduler_thread::run_undetached(void *arg)
+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
+    sigset_t old_set;
+    sigset_t new_set;
+    sigfillset(&new_set);
+    sigdelset(&new_set, SIGINT);
+    sigprocmask(SIG_BLOCK, &new_set, &old_set);
+
+    // Run the single-threaded scheduler
     d_sts->run();
     return 0;
 }

Modified: 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
    2006-12-17 23:31:51 UTC (rev 4117)
+++ 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_runtime_impl.h
    2006-12-18 00:24:33 UTC (rev 4118)
@@ -28,23 +28,20 @@
 #include <omnithread.h>
 #include <gr_single_threaded_scheduler.h>
 
+// omnithread calls delete on itself after thread exits, so can't use shared 
ptr
 class gr_scheduler_thread;
-typedef boost::shared_ptr<gr_scheduler_thread> gr_scheduler_thread_sptr;
-typedef std::vector<gr_scheduler_thread_sptr> gr_scheduler_thread_vector_t;
-typedef std::vector<gr_scheduler_thread_sptr>::iterator 
gr_scheduler_thread_viter_t;
+typedef std::vector<gr_scheduler_thread *> gr_scheduler_thread_vector_t;
+typedef gr_scheduler_thread_vector_t::iterator gr_scheduler_thread_viter_t;
 
-gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t graph);
-
 class gr_scheduler_thread : public omni_thread
 {
 private:
-    gr_scheduler_thread(gr_block_vector_t graph);
-    friend gr_scheduler_thread_sptr gr_make_scheduler_thread(gr_block_vector_t 
graph);
-
     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();

Modified: 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
        2006-12-17 23:31:51 UTC (rev 4117)
+++ 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-core/src/lib/runtime/gr_simple_flowgraph_detail.cc
        2006-12-18 00:24:33 UTC (rev 4118)
@@ -291,8 +291,8 @@
         gr_edge_vector_t in_edges = calc_upstream_edges(p->first);
 
         if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG)
-           if (in_edges.size() > 0)
-               std::cout << "Connecting inputs to " << p->first << "..." << 
std::endl;
+               if (in_edges.size() > 0)
+                   std::cout << "Connecting inputs to " << p->first << "..." 
<< std::endl;
 
         // For each edge that feeds into it
         for (gr_edge_viter_t e = in_edges.begin(); e != in_edges.end(); e++) {
@@ -488,24 +488,29 @@
 void
 gr_simple_flowgraph_detail::dump_block_vector(gr_block_vector_t blocks)
 {
-    for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) {
-        std::cout << (*p) << std::endl;
-    }
+    if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG)
+        for (gr_block_viter_t p = blocks.begin(); p != blocks.end(); p++) {
+            std::cout << (*p) << std::endl;
+        }
 }
 
 gr_block_vector_t
 gr_simple_flowgraph_detail::topological_sort(gr_block_vector_t &blocks)
 {
     gr_block_vector_t result, tmp;
-    std::cout << "Before source sort: " << std::endl;
-    dump_block_vector(blocks);
-    std::cout << std::endl;
+    if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) {
+        std::cout << "Before source sort: " << std::endl;
+        dump_block_vector(blocks);
+        std::cout << std::endl;
+    }
 
     tmp = sort_sources_first(blocks);
 
-    std::cout << "After source sort: " << std::endl;
-    dump_block_vector(tmp);
-    std::cout << std::endl;
+    if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) {
+        std::cout << "After source sort: " << std::endl;
+        dump_block_vector(tmp);
+        std::cout << std::endl;
+    }
 
     // Start 'em all white
     for (gr_block_viter_t p = tmp.begin(); p != tmp.end(); p++)
@@ -518,9 +523,11 @@
 
     reverse(result.begin(), result.end());
 
-    std::cout << "After dfs: " << std::endl;
-    dump_block_vector(result);
-    std::cout << std::endl;
+    if (GR_SIMPLE_FLOWGRAPH_DETAIL_DEBUG) {
+        std::cout << "After dfs: " << std::endl;
+        dump_block_vector(result);
+        std::cout << std::endl;
+    }
 
     return result;
 }


Property changes on: 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone
___________________________________________________________________
Name: svn:ignore
   - .deps
.libs
Makefile
Makefile.in
dialtone

   + .deps
.libs
Makefile
Makefile.in
dialtone
test_head


Modified: 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/Makefile.am
 2006-12-17 23:31:51 UTC (rev 4117)
+++ 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/Makefile.am
 2006-12-18 00:24:33 UTC (rev 4118)
@@ -32,10 +32,11 @@
 # GNURADIO_CORE_LIBS = -lgnuradio-core
 # GR_AUDIO_ALSA_LIBS = -lgr_audio_alsa
 
-noinst_PROGRAMS = dialtone
+noinst_PROGRAMS = dialtone test_head
     
 noinst_HEADERS = \
-    dialtone.h
+    dialtone.h \
+    test_head.h
         
 dialtone_SOURCES = \
     dialtone.cc           \
@@ -45,4 +46,10 @@
     $(GNURADIO_CORE_LIBS) \
     $(GR_AUDIO_ALSA_LIBS)
 
+test_head_SOURCES = \
+    test_head.cc
+
+test_head_LDADD = \
+    $(GNURADIO_CORE_LIBS) 
+
 MOSTLYCLEANFILES = *~

Added: 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/test_head.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/test_head.cc
                                (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/test_head.cc
        2006-12-18 00:24:33 UTC (rev 4118)
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2006 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 GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// GNU Radio C++ application
+//
+// Instantiate a top block
+// Instantiate a runtime, passing it the top block
+// Tell the runtime to go...
+
+#include <test_head.h>
+
+#include <gr_runtime.h>
+#include <gr_io_signature.h>
+#include <gr_sig_source_f.h>
+#include <gr_null_sink.h>
+#include <gr_head.h>
+
+// Shared pointer constructor
+test_head_sptr make_test_head()
+{
+    return test_head_sptr(new test_head());
+}
+
+// Hierarchical block constructor, with no inputs or outputs
+test_head::test_head() : 
+gr_hier_block2("test_head",
+              gr_make_io_signature(0,0,0),
+              gr_make_io_signature(0,0,0))
+{
+    define_component("src", gr_make_sig_source_f(48000, GR_SIN_WAVE, 350, 
0.5));
+    define_component("head", gr_make_head(sizeof(float), 1000000L));
+    define_component("sink", gr_make_null_sink(sizeof(float)));
+
+    connect("src", 0, "head", 0);
+    connect("head", 0, "sink", 0);    
+}
+
+int main()
+{
+    test_head_sptr top_block = make_test_head();
+    gr_runtime_sptr runtime = gr_make_runtime(top_block);
+
+    runtime->run();   
+    return 0;
+}

Added: 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/test_head.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/test_head.h
                         (rev 0)
+++ 
gnuradio/branches/developers/jcorgan/sfg/gnuradio-examples/c++/dialtone/test_head.h
 2006-12-18 00:24:33 UTC (rev 4118)
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2006 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 GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <gr_hier_block2.h>
+
+class test_head;
+typedef boost::shared_ptr<test_head> test_head_sptr;
+test_head_sptr make_test_head();
+
+class test_head : public gr_hier_block2
+{
+private:
+    test_head();
+    friend test_head_sptr make_test_head();
+};

Modified: 
gnuradio/branches/developers/jcorgan/sfg/gr-audio-alsa/src/audio_alsa_sink.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/sfg/gr-audio-alsa/src/audio_alsa_sink.cc   
    2006-12-17 23:31:51 UTC (rev 4117)
+++ 
gnuradio/branches/developers/jcorgan/sfg/gr-audio-alsa/src/audio_alsa_sink.cc   
    2006-12-18 00:24:33 UTC (rev 4118)
@@ -32,7 +32,10 @@
 #include <stdexcept>
 #include <gri_alsa.h>
 
+// FIXME remove
+#include <omnithread.h>
 
+
 static bool CHATTY_DEBUG = false;
 
 
@@ -512,6 +515,9 @@
 
     else if (r < 0){
       output_error_msg ("snd_pcm_writei failed", r);
+      fprintf(stderr, "thread_id = %p\n",
+             omni_thread::self());
+
       return false;
     }
 





reply via email to

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