[mythtv] [patch] thread safe verbose macro v4
Daniel Thor Kristjansson
danielk at mrl.nyu.edu
Tue Mar 1 01:57:06 UTC 2005
I'm just resubmitting this now that 0.17 is out. This uses
a QMutex recursive lock to make sure that two or more
VERBOSE macros don't try to write to stdout at once.
The old patch still applied with a few offset complaints,
but I reformatted the macro so that it doesn't exceed 80
columns, which also let me use some temps to put less of
the code inside the locked section.
-- Daniel
-------------- next part --------------
Index: libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.155
diff -u -r1.155 mythcontext.cpp
--- libs/libmyth/mythcontext.cpp 23 Feb 2005 05:04:35 -0000 1.155
+++ libs/libmyth/mythcontext.cpp 1 Mar 2005 01:45:50 -0000
@@ -42,6 +42,7 @@
#endif
MythContext *gContext = NULL;
+QMutex MythContext::verbose_mutex(true);
int print_verbose_messages = VB_IMPORTANT | VB_GENERAL;
Index: libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.182
diff -u -r1.182 mythcontext.h
--- libs/libmyth/mythcontext.h 23 Feb 2005 05:04:35 -0000 1.182
+++ libs/libmyth/mythcontext.h 1 Mar 2005 01:45:50 -0000
@@ -12,6 +12,7 @@
#include <qsocketdevice.h>
#include <qstringlist.h>
#include <qnetwork.h>
+#include <qmutex.h>
#include <iostream>
#include <vector>
@@ -83,9 +84,14 @@
#define VERBOSE(mask,args...) \
do { \
-if ((print_verbose_messages & mask) != 0) \
- cout << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") \
- << " " << args << endl; \
+ if ((print_verbose_messages & mask) != 0) \
+ { \
+ QDateTime dtmp = QDateTime::currentDateTime(); \
+ QString dtime = dtmp.toString("yyyy-MM-dd hh:mm:ss.zzz"); \
+ MythContext::verbose_mutex.lock(); \
+ cout << dtime << " " << args << endl; \
+ MythContext::verbose_mutex.unlock(); \
+ } \
} while (0)
class MythEvent : public QCustomEvent
@@ -273,6 +279,8 @@
void waitPrivRequest() const;
MythPrivRequest popPrivRequest();
+ static QMutex verbose_mutex; // makes verbose output more sane
+
private slots:
void EventSocketRead();
void EventSocketConnected();
More information about the mythtv-dev
mailing list