[mythtv] [patch] thread safe verbose

Daniel Thor Kristjansson danielk at mrl.nyu.edu
Fri Jan 14 12:23:53 EST 2005


I've been annoyed with error messages that are corrupted because two 
threads are trying to output a message at the same time. This patch
addresses the ones that use the VERBOSE macro by adding a mutex
to the macro so that only one thread outputs using the VERBOSE macro
at once.

The compile will take a while after you apply this, but the code will be 
much easier to debug.

-- Daniel
-------------- next part --------------
Index: libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.143
diff -r1.143 mythcontext.cpp
41a42
> pthread_mutex_t MythContext::verbose_lock = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
Index: libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.174
diff -r1.174 mythcontext.h
14a15
> #include <pthread.h>
84,86c85,91
< 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) \
>     {\
>         pthread_mutex_lock(&MythContext::verbose_lock);\
>         cout << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz") \
>              << " " << args << endl; \
>         pthread_mutex_unlock(&MythContext::verbose_lock);\
>     }\
269a275,276
>     static pthread_mutex_t verbose_lock; // makes verbose output more sane
> 
289d295
< 


More information about the mythtv-dev mailing list