Configure option to abort when malloc is called in the process thread.
authorCarl Hetherington <carl@carlh.net>
Wed, 19 Jan 2011 21:36:38 +0000 (21:36 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 19 Jan 2011 21:36:38 +0000 (21:36 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@8548 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/graph.h
libs/ardour/graph.cc
libs/pbd/wscript
wscript

index 6893c08d9dfd9c30ea5f2874ed65c89a7069fa40..812bc5b86c7de04626dfb2cb206e732eca8c021c 100644 (file)
@@ -84,6 +84,8 @@ class Graph : public SessionHandleRef
 
         void clear_other_chain ();
 
+       bool in_process_thread () const;
+
     protected:
         virtual void session_going_away ();
 
index 0d3749aff0b68fc7c7cab1b5ea37d64187be55a0..7cddd522e1275b295317d3a2356ac1994d2e0259 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "pbd/compose.h"
 #include "pbd/cpus.h"
+#include "pbd/debug_rt_alloc.h"
 
 #include "ardour/debug.h"
 #include "ardour/graph.h"
@@ -39,6 +40,17 @@ using namespace ARDOUR;
 using namespace PBD;
 using namespace std;
 
+#ifdef DEBUG_RT_ALLOC
+static Graph* graph = 0;
+extern "C" {
+
+int alloc_allowed ()
+{
+       return !graph->in_process_thread ();
+}
+
+}
+#endif
 
 Graph::Graph (Session & session) 
         : SessionHandleRef (session) 
@@ -97,6 +109,11 @@ Graph::Graph (Session & session)
                        _thread_list.push_back (a_thread);
                }
         }
+
+#ifdef DEBUG_RT_ALLOC  
+       graph = this;
+       pbd_alloc_allowed = &::alloc_allowed;
+#endif 
 }
 
 void
@@ -380,7 +397,7 @@ static void get_rt()
 void
 Graph::helper_thread()
 {
-        ProcessThread *pt = new ProcessThread;
+       ProcessThread* pt = new ProcessThread ();
 
         pt->get_buffers();
         get_rt();
@@ -397,7 +414,7 @@ Graph::helper_thread()
 void
 Graph::main_thread()
 {
-        ProcessThread *pt = new ProcessThread;
+       ProcessThread* pt = new ProcessThread ();
 
         pt->get_buffers();
         get_rt();
@@ -557,5 +574,13 @@ Graph::process_one_route (Route* route)
         }
 }
 
+bool
+Graph::in_process_thread () const
+{
+       list<pthread_t>::const_iterator i = _thread_list.begin ();
+       while (i != _thread_list.end() && *i != pthread_self ()) {
+               ++i;
+       }
 
-
+       return i != _thread_list.end ();
+}
index b952b637532a1cffc82f1e8d28f227068cc97f23..69eafe4285ab6d0e7424ff1986ce1cdfe309eeae 100644 (file)
@@ -106,6 +106,10 @@ def build(bld):
                whitespace.cc
                xml++.cc
        '''
+
+       if bld.env['DEBUG_RT_ALLOC']:
+               obj.source += 'debug_rt_alloc.c'
+
        obj.export_incdirs = ['.']
        obj.includes     = ['.']
        obj.name         = 'libpbd'
diff --git a/wscript b/wscript
index bf1a1024da3b3f96ca9cf30a2d382c72f5a9ab3b..4c86cc37c9bfafd53348464d2d904f69086a0153 100644 (file)
--- a/wscript
+++ b/wscript
@@ -291,6 +291,11 @@ def set_compiler_flags (conf,opt):
        if opt.stl_debug:
                conf.env.append_value('CXXFLAGS', "-D_GLIBCXX_DEBUG")
 
+       if conf.env['DEBUG_RT_ALLOC']:
+               conf.env.append_value('CCFLAGS', '-DDEBUG_RT_ALLOC')
+               conf.env.append_value('CXXFLAGS', '-DDEBUG_RT_ALLOC')
+               conf.env.append_value('LINKFLAGS', '-ldl')
+
        if opt.universal:
                conf.env.append_value('CCFLAGS', "-arch i386 -arch ppc")
                conf.env.append_value('CXXFLAGS', "-arch i386 -arch ppc")
@@ -325,7 +330,6 @@ def set_compiler_flags (conf,opt):
                conf.env.append_value('CXXFLAGS', '-DENABLE_NLS')
                conf.env.append_value('CCFLAGS', '-DENABLE_NLS')
 
-
 #----------------------------------------------------------------
 
 # Waf stages
@@ -359,6 +363,8 @@ def set_options(opt):
        opt.add_option('--phone-home', action='store_false', default=True, dest='phone_home')
        opt.add_option('--stl-debug', action='store_true', default=False, dest='stl_debug',
                        help='Build with debugging for the STL')
+       opt.add_option('--rt-alloc-debug', action='store_true', default=False, dest='rt_alloc_debug',
+                       help='Build with debugging for memory allocation in the real-time thread')
        opt.add_option('--test', action='store_true', default=False, dest='build_tests', 
                        help="Build unit tests")
        opt.add_option('--tranzport', action='store_true', default=False, dest='tranzport',
@@ -540,6 +546,8 @@ def configure(conf):
        autowaf.display_msg(conf, 'Windows Key', opts.windows_key)
        conf.env['PROGRAM_NAME'] = opts.program_name
        autowaf.display_msg(conf, 'Program Name', opts.program_name)
+       if opts.rt_alloc_debug:
+               conf.define('DEBUG_RT_ALLOC', 1)
 
        set_compiler_flags (conf, Options.options)