Il 07/11/2011 14:46, Tommaso Cucinotta ha scritto:
However, now I broke compilation of lyxclient which complains with
errors about not knowing anything about #include <QThread> and you can
imagine what else...
this is fixed in the attached refined version of the "SMP debugging" patch.
Interestingly, both lyxclient and tex2lyx already used to link with Qt
libraries, but the Qt include flags were not there, so I had only to add
the latter.
Any opinion against committing this patch that uses a mutex for
synchronizing LYXERR() output across multiple threads ?
T.
Index: src/tex2lyx/Makefile.am
===================================================================
--- src/tex2lyx/Makefile.am (revisione 40135)
+++ src/tex2lyx/Makefile.am (copia locale)
@@ -17,6 +17,7 @@
DEFAULT_INCLUDES =
AM_CPPFLAGS += -DTEX2LYX $(PCH_FLAGS) -I$(top_srcdir)/src/tex2lyx \
+ $(QT4_CPPFLAGS) $(QT4_INCLUDES) \
-I$(top_srcdir)/src -I$(top_builddir) $(BOOST_INCLUDES)
TEST_FILES = \
Index: src/client/Makefile.am
===================================================================
--- src/client/Makefile.am (revisione 40135)
+++ src/client/Makefile.am (copia locale)
@@ -8,7 +8,8 @@
EXTRA_DIST = lyxclient.1in
-AM_CPPFLAGS += -I$(srcdir)/.. $(BOOST_INCLUDES)
+AM_CPPFLAGS += -I$(srcdir)/.. $(BOOST_INCLUDES) \
+ $(QT4_CPPFLAGS) $(QT4_INCLUDES)
lyxclient_LDADD = \
$(top_builddir)/src/support/liblyxsupport.a \
Index: src/support/debug.h
===================================================================
--- src/support/debug.h (revisione 40135)
+++ src/support/debug.h (copia locale)
@@ -16,7 +16,13 @@
#define LYXDEBUG_H
#include "support/strfwd.h"
+#include <QThread>
+#include <QMutex>
+#include <QMutexLocker>
+// To be moved to automake/autoconf & the like
+#define LYX_PARALLEL
+
namespace std {
class ios_base;
@@ -202,6 +208,10 @@
extern LyXErr lyxerr;
+#ifdef LYX_PARALLEL
+extern QMutex lyxerr_mtx;
+#endif
+
} // namespace lyx
#if USE_BOOST_CURRENT_FUNCTION
@@ -211,9 +221,30 @@
# define CURRENT_POSITION __FILE__ << "(" << __LINE__ << "): "
#endif
+#ifdef LYX_PARALLEL
+
#define LYXERR(type, msg) \
do { \
if (!lyx::lyxerr.debugging(type)) {} \
+ else { \
+ QMutexLocker lock(&lyx::lyxerr_mtx); \
+ lyx::lyxerr << "[thread " << QThread::currentThreadId() << "] "; \
+ lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \
+ } \
+ } while (0)
+
+#define LYXERR0(msg) \
+ do { \
+ QMutexLocker lock(&lyx::lyxerr_mtx); \
+ lyx::lyxerr << "[thread " << QThread::currentThreadId() << "] "; \
+ lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \
+ } while (0)
+
+#else
+
+#define LYXERR(type, msg) \
+ do { \
+ if (!lyx::lyxerr.debugging(type)) {} \
else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
} while (0)
@@ -222,5 +253,6 @@
lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \
} while (0)
+#endif
#endif
Index: src/support/debug.cpp
===================================================================
--- src/support/debug.cpp (revisione 40135)
+++ src/support/debug.cpp (copia locale)
@@ -28,6 +28,10 @@
namespace lyx {
+#ifdef LYX_PARALLEL
+QMutex lyxerr_mtx;
+#endif
+
namespace {
struct ErrorItem {