new stacktrace function in libpbd3; variable size GUI request thread queues
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 15 Feb 2006 15:55:48 +0000 (15:55 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 15 Feb 2006 15:55:48 +0000 (15:55 +0000)
git-svn-id: svn://localhost/trunk/ardour2@330 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/audioengine.cc
libs/ardour/session_midi.cc
libs/gtkmm2ext/gtk_ui.cc
libs/gtkmm2ext/gtkmm2ext/gtk_ui.h
libs/pbd3/SConscript
libs/pbd3/pbd/pthread_utils.h
libs/pbd3/pbd/stacktrace.h [new file with mode: 0644]
libs/pbd3/pthread_utils.cc
libs/pbd3/stacktrace.cc [new file with mode: 0644]

index e3c9549663558f0bfcab6b7819229e6a6971e9ec..c64b4d6429b849bfb3285904877a9c1497047784 100644 (file)
@@ -80,7 +80,7 @@ _thread_init_callback (void *arg)
           knows about it.
        */
 
-       PBD::ThreadCreated (pthread_self(), X_("Audioengine"));
+       PBD::ThreadCreatedWithRequestSize (pthread_self(), X_("Audioengine"), 4096);
 
 #ifdef VST_SUPPORT
        if (Config->get_use_vst()) {
index 2b7afa354aa6cda898ff0544feb48d7397596bf4..b2b1d263a7666c2d4c72478168dad4b4ec91bce8 100644 (file)
@@ -1272,7 +1272,7 @@ Session::midi_thread_work ()
        bool restart;
        vector<MIDI::Port*> ports;
 
-       PBD::ThreadCreated (pthread_self(), X_("MIDI"));
+       PBD::ThreadCreatedWithRequestSize (pthread_self(), X_("MIDI"), 2048);
 
        memset (&rtparam, 0, sizeof (rtparam));
        rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
index 1a46e1b90089f15e314d7fd2dd657eff2885ad80..8dd5a18526632ba0888cbd76f8941779778a3d09 100644 (file)
@@ -31,6 +31,7 @@
 #include <pbd/touchable.h>
 #include <pbd/failed_constructor.h>
 #include <pbd/pthread_utils.h>
+#include <pbd/stacktrace.h>
 
 #include <gtkmm2ext/gtk_ui.h>
 #include <gtkmm2ext/textviewer.h>
@@ -59,6 +60,7 @@ UI::UI (string name, int *argc, char ***argv, string rcfile)
        }
 
        PBD::ThreadCreated.connect (mem_fun (*this, &UI::register_thread));
+       PBD::ThreadCreatedWithRequestSize.connect (mem_fun (*this, &UI::register_thread_with_request_count));
 
        _ok = false;
        _active = false;
@@ -370,7 +372,13 @@ UI::timeout_add (unsigned int timeout, int (*func)(void *), void *arg)
 void
 UI::register_thread (pthread_t thread_id, string name)
 {
-       RingBufferNPT<Request>* b = new RingBufferNPT<Request> (128);
+       register_thread_with_request_count (thread_id, name, 256);
+}
+
+void
+UI::register_thread_with_request_count (pthread_t thread_id, string name, uint32_t num_requests)
+{
+       RingBufferNPT<Request>* b = new RingBufferNPT<Request> (num_requests);
 
        {
                PBD::LockMonitor lm (request_buffer_map_lock, __LINE__, __FILE__);
index 1ea451528433a3d4cd1ca16ce615d12a130bb1e6..4e63af79241a4dc902618ce5c4a318c76113f151 100644 (file)
@@ -70,7 +70,9 @@ class UI : public AbstractUI
        void call_slot_locked (sigc::slot<void>);
        void touch_display (Touchable *);
        void receive (Transmitter::Channel, const char *);
+
        void register_thread (pthread_t, string);
+       void register_thread_with_request_count (pthread_t, string, uint32_t num_requests);
 
        bool caller_is_gui_thread () { 
                return pthread_equal (gui_thread, pthread_self());
index f4b7bf24a8a2cbed0d5ef4b717fb8ab274a4ca72..995bc8b933fbad6088536aef18055c604cb20ce9 100644 (file)
@@ -18,6 +18,7 @@ pathscanner.cc
 pool.cc
 pthread_utils.cc
 receiver.cc
+stacktrace.cc
 strsplit.cc
 textreceiver.cc
 transmitter.cc
@@ -31,6 +32,8 @@ xml++.cc
 conf = Configure(pbd3)
 if conf.CheckFunc('getmntent'):
     conf.env.Append(CCFLAGS="-DHAVE_GETMNTENT")
+if conf.CheckCHeader('execinfo.h'):
+    conf.env.Append(CXXFLAGS="-DHAVE_EXECINFO")
 pbd3 = conf.Finish()
 
 pbd3.Merge ([ libraries['sigc2'], libraries['xml'] ])
index 9c7cefd3e4de93499f2aa50f5f6252a226b75d01..258604fc74a4942c1b7c0ebd86f139e85e5b81ac 100644 (file)
@@ -16,6 +16,7 @@ std::string pthread_name ();
 
 namespace PBD {
   extern sigc::signal<void,pthread_t,std::string> ThreadCreated;
+  extern sigc::signal<void,pthread_t,std::string,uint32_t> ThreadCreatedWithRequestSize;
 }
 
 #endif /* __pbd_pthread_utils__ */
diff --git a/libs/pbd3/pbd/stacktrace.h b/libs/pbd3/pbd/stacktrace.h
new file mode 100644 (file)
index 0000000..d7278bd
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __libpbd_stacktrace_h__
+#define __libpbd_stacktrace_h__
+
+#include <ostream>
+
+namespace PBD {
+       void stacktrace (std::ostream& out);
+}
+
+#endif /* __libpbd_stacktrace_h__ */
index 6ef29e3605a83737d1af4ab7a16103e0189dc3a8..1fc9227ba5a103edbde1e35aa1e9685e1c6244a6 100644 (file)
@@ -21,6 +21,7 @@
 #include <map>
 #include <iostream>
 #include <string>
+#include <stdint.h>
 
 #include <pbd/pthread_utils.h>
 
@@ -34,6 +35,7 @@ static pthread_mutex_t thread_map_lock = PTHREAD_MUTEX_INITIALIZER;
 
 namespace PBD {
    sigc::signal<void,pthread_t,std::string> ThreadCreated;
+   sigc::signal<void,pthread_t,std::string,uint32_t> ThreadCreatedWithRequestSize;
 }
 
 using namespace PBD;
diff --git a/libs/pbd3/stacktrace.cc b/libs/pbd3/stacktrace.cc
new file mode 100644 (file)
index 0000000..1e7dfa0
--- /dev/null
@@ -0,0 +1,42 @@
+#include <pbd/stacktrace.h>
+#include <iostream>
+
+/* Obtain a backtrace and print it to stdout. */
+
+#ifdef HAVE_EXECINFO
+
+#include <execinfo.h>
+#include <stdlib.h>
+
+void
+PBD::stacktrace (std::ostream& out)
+{
+       void *array[200];
+       size_t size;
+       char **strings;
+       size_t i;
+     
+       size = backtrace (array, 200);
+       strings = backtrace_symbols (array, size);
+     
+       if (strings) {
+
+               printf ("Obtained %zd stack frames.\n", size);
+               
+               for (i = 0; i < size; i++) {
+                       out << strings[i] << std::endl;
+               }
+               
+               free (strings);
+       }
+}
+
+#else
+
+void
+PBD::stacktrace (std::ostream& out)
+{
+       out << "stack tracing is not enabled on this platform" << std::endl;
+}
+
+#endif /* HAVE_EXECINFO */