diff base/Debug.h @ 1061:c1e43c8d2527 tonioni

Thread-local debug was causing crash on exit with Qt 5.4.x. But we introduced that because QDebug itself was crashing when used from multiple threads. Replace with simpler fstream version
author Chris Cannam
date Tue, 31 Mar 2015 10:36:52 +0100
parents 16dc7307d43a
children 8f076d02569a
line wrap: on
line diff
--- a/base/Debug.h	Wed Mar 25 10:54:51 2015 +0000
+++ b/base/Debug.h	Tue Mar 31 10:36:52 2015 +0100
@@ -13,8 +13,8 @@
     COPYING included with this distribution for more information.
 */
 
-#ifndef _DEBUG_H_
-#define _DEBUG_H_
+#ifndef SV_DEBUG_H
+#define SV_DEBUG_H
 
 #include <QDebug>
 #include <QTextStream>
@@ -23,6 +23,7 @@
 
 #include <string>
 #include <iostream>
+#include <fstream>
 
 class QString;
 class QUrl;
@@ -37,29 +38,40 @@
 
 #ifndef NDEBUG
 
-extern QDebug &getSVDebug();
+class SVDebug {
+public:
+    SVDebug();
+    ~SVDebug();
+
+    template <typename T>
+    inline SVDebug &operator<<(const T &t) {
+        if (m_ok) {
+            if (m_eol) {
+                m_stream << m_prefix << " ";
+            }
+            m_stream << t;
+            m_eol = false;
+        }
+        return *this;
+    }
+
+    inline SVDebug &operator<<(QTextStreamFunction) {
+        m_stream << std::endl;
+        m_eol = true;
+        return *this;
+    }
+
+private:
+    std::fstream m_stream;
+    char *m_prefix;
+    bool m_ok;
+    bool m_eol;
+};
+
+extern SVDebug &getSVDebug();
 
 #define SVDEBUG getSVDebug()
 
-inline QDebug &operator<<(QDebug &d, const RealTime &rt) {
-    d << rt.toString();
-    return d;
-}
-
-inline QDebug &operator<<(QDebug &d, const Vamp::RealTime &rt) {
-    d << rt.toString();
-    return d;
-}
-
-template <typename T>
-inline QDebug &operator<<(QDebug &d, const T &t) {
-    QString s;
-    QTextStream ts(&s);
-    ts << t;
-    d << s;
-    return d;
-}
-
 #else
 
 class NoDebug