[mythtv] [patch] thread safe verbose v2

Daniel Thor Kristjansson danielk at mrl.nyu.edu
Fri Jan 21 11:27:32 EST 2005


On Fri, 21 Jan 2005, Isaac Richards wrote:
]On Tuesday 18 January 2005 10:50 am, Daniel Thor Kristjansson wrote:
]How 'bout a QMutex? =)  I'd really like to eventually move away from direct 
]pthread usage..  helps possible porting.

Attached.

-- Daniel
-------------- next part --------------
Index: libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.143
diff -u -r1.143 mythcontext.cpp
--- libs/libmyth/mythcontext.cpp	30 Dec 2004 16:17:22 -0000	1.143
+++ libs/libmyth/mythcontext.cpp	21 Jan 2005 16:26:12 -0000
@@ -39,6 +39,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.174
diff -u -r1.174 mythcontext.h
--- libs/libmyth/mythcontext.h	29 Dec 2004 21:00:45 -0000	1.174
+++ libs/libmyth/mythcontext.h	21 Jan 2005 16:26:12 -0000
@@ -12,6 +12,7 @@
 #include <qsocketdevice.h>
 #include <qstringlist.h>
 #include <qnetwork.h> 
+#include <qmutex.h>
 
 #include <iostream>
 #include <vector>
@@ -81,9 +82,13 @@
 
 #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) \
+    {\
+        MythContext::verbose_mutex.lock();\
+        cout << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") \
+             << " " << args << endl; \
+        MythContext::verbose_mutex.unlock();\
+    }\
 } while (0)
 
 class MythEvent : public QCustomEvent
@@ -267,6 +272,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