[mythtv] [patch] thread safe verbose v2

Daniel Thor Kristjansson danielk at mrl.nyu.edu
Tue Jan 18 10:50:55 EST 2005


As noted by Eric Anderson, someone might call a function that uses 
VERBOSE inside a VERBOSE macro. This updated patch uses a recursive
lock to prevent this case from deadlocking the application.

If someone engages in blocking inter-thread communications with
another thread that also uses VERBOSE while within the VERBOSE
macro this would still deadlock. But I think we would want to
find any such coding monstrosities.

I've not had any deadlocks even with a the fast lock in my first 
thread safe verbose patch.

-- 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_RECURSIVE_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