[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-multimedia
Subject: Re: [jan.smid@student.uni-magdeburg.de: Bug#28076: arts crashes when playing system sounds (windows
From: Stefan Westerfeld <stefan () space ! twc ! de>
Date: 2001-07-24 19:19:57
[Download RAW message or body]
Hi!
Well, right now it wouldn't work, because it would create a new mutex for
each arts_debug/... call, which kind-of defeats the purpose.
I changed it a bit - the tricky thing is that we need to allocate the
mutex after the thread system is initialized (thus allocating it in a global
constructor is not possible), but before arts_debug/... is used for the first
time from a thread. A StartupClass could already create a thread, so
initialization in a StartupClass is also not an option.
So I think doing it explicitely might be the simplest thing do to. Do you
think it's ok like this?
Cu... Stefan
On Mon, Jul 23, 2001 at 10:35:15AM -0400, Jeff Tranter wrote:
> Here is a version of the patch with a mutex.
>
> On July 22, 2001 06:25 am, Stefan Westerfeld wrote:
> > Hi!
> >
> > There are two issues with the patch:
> >
> > - it doesn't give immediate feedback to the user when messages are
> > repeating (i.e. you don't know whether a message is repeating and repeating
> > all the time, because you only see the first version of it, until another
> > message pops up)
> >
> > - it makes the debugging routines non-thread-safe, because it adds static
> > variables
> >
> > The first is not too important, and it can be corrected later (after
> > KDE2.2), if somebody wants to solve this.
> >
> > The thread safety issue can be solved by adding a mutex, and I think it
> > should be done, because I would like to be able to use the debugging
> > routines like arts_debug or arts_return_if_fail even in code that doesn't
> > run in the main thread.
> >
> > If you know how to do this, please do and repost the patch, if not, go
> > ahead and apply the patch, and I'll add the mutex.
> >
> > Cu... Stefan
--
-* Stefan Westerfeld, stefan@space.twc.de (PGP!), Hamburg/Germany
KDE Developer, project infos at http://space.twc.de/~stefan/kde *-
["20010724-debug-lastmsg-check.diff" (text/plain)]
? message.patch
Index: debug.cc
===================================================================
RCS file: /home/kde/kdelibs/arts/mcop/debug.cc,v
retrieving revision 1.5
diff -u -r1.5 debug.cc
--- debug.cc 2001/03/20 12:53:30 1.5
+++ debug.cc 2001/07/24 19:10:02
@@ -25,11 +25,13 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include "thread.h"
static int arts_debug_level = Arts::Debug::lInfo;
static bool arts_debug_abort = false;
static const char *arts_debug_prefix = "";
static char *messageAppName = 0;
+static Arts::Mutex *arts_debug_mutex = 0;
namespace Arts {
@@ -39,8 +41,8 @@
* always sent to standard error because they tend to be very verbose.
* Note that the external application is run in the background to
* avoid blocking the sound server.
-*/
-void display_message(Debug::Level level, const char *msg) {
+ */
+void output_message(Debug::Level level, const char *msg) {
char buff[1024];
/* default to text output if no message app is defined or if it is a debug message. */
@@ -66,6 +68,42 @@
system(buff);
}
+/*
+ * Display a message using output_message. If the message is the same
+ * as the previous one, just increment a count but don't display
+ * it. This prevents flooding the user with duplicate warnings. If the
+ * message is not the same as the previous one, then we report the
+ * previously repeated message (if any) and reset the last message and
+ * count.
+ */
+void display_message(Debug::Level level, const char *msg) {
+ static char lastMsg[1024];
+ static Debug::Level lastLevel;
+ static int msgCount = 0;
+
+ if(arts_debug_mutex)
+ arts_debug_mutex->lock();
+
+ if (!strncmp(msg, lastMsg, 1024))
+ {
+ msgCount++;
+ } else {
+ if (msgCount > 0)
+ {
+ char buff[1024];
+ sprintf(buff, "%s\n(The previous message was repeated %d times.)", lastMsg, msgCount);
+ output_message(lastLevel, buff);
+ }
+ strncpy(lastMsg, msg, 1024);
+ lastLevel = level;
+ msgCount = 0;
+ output_message(level, msg);
+ }
+
+ if(arts_debug_mutex)
+ arts_debug_mutex->unlock();
+}
+
static class DebugInitFromEnv {
public:
DebugInitFromEnv() {
@@ -156,4 +194,19 @@
{
messageAppName = (char*) realloc(messageAppName, strlen(appName)+1);
strcpy(messageAppName, appName);
+}
+
+void Arts::Debug::initMutex()
+{
+ arts_return_if_fail(arts_debug_mutex == 0);
+
+ arts_debug_mutex = new Arts::Mutex();
+}
+
+void Arts::Debug::freeMutex()
+{
+ arts_return_if_fail(arts_debug_mutex != 0);
+
+ delete arts_debug_mutex;
+ arts_debug_mutex = 0;
}
Index: debug.h
===================================================================
RCS file: /home/kde/kdelibs/arts/mcop/debug.h,v
retrieving revision 1.3
diff -u -r1.3 debug.h
--- debug.h 2001/03/20 12:53:30 1.3
+++ debug.h 2001/07/24 19:10:03
@@ -97,6 +97,10 @@
public:
enum Level { lFatal = 3, lWarning = 2, lInfo = 1, lDebug = 0 };
+ /**
+ * Initializes at which is the minimum level to react to. If you
+ * call this, call this before creating the Arts::Dispatcher object.
+ */
static void init(const char *prefix, Level level);
static void fatal(const char *fmt,...); // print on stderr & abort
@@ -104,11 +108,14 @@
static void info(const char *fmt,...); // print on stdout
static void debug(const char *fmt,...); // print on stdout
-/*
- * This method sets the name of an external application to display messages
- * graphically.
- */
+ /**
+ * This method sets the name of an external application to
+ * display messages graphically.
+ */
static void messageApp(const char *appName);
+
+ static void initMutex(); // called from the dispatcher constructor
+ static void freeMutex(); // called from the dispatcher destructor
};
};
Index: dispatcher.cc
===================================================================
RCS file: /home/kde/kdelibs/arts/mcop/dispatcher.cc,v
retrieving revision 1.59
diff -u -r1.59 dispatcher.cc
--- dispatcher.cc 2001/04/28 18:07:03 1.59
+++ dispatcher.cc 2001/07/24 19:10:06
@@ -153,6 +153,9 @@
lock();
+ /* makes arts_debug/arts_message/arts_return_if_fail/... threadsafe */
+ Debug::initMutex();
+
generateServerID();
if(ioManager)
@@ -387,6 +390,9 @@
<< GenericDataPacket::_dataPacketCount()
<< " data packets alive." << endl;
}
+
+ Debug::freeMutex();
+
unlock();
/* private data pointer */
_______________________________________________
Kde-multimedia mailing list
Kde-multimedia@master.kde.org
http://master.kde.org/mailman/listinfo/kde-multimedia
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic