[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: Jeff Tranter <tranter () pobox ! com>
Date: 2001-07-23 14:35:15
[Download RAW message or body]
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
["message.patch" (text/x-diff)]
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/23 14:26:50
@@ -25,6 +25,7 @@
#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;
@@ -39,8 +40,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. */
@@ -64,6 +65,39 @@
break; // avoid compile warning
}
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;
+ Arts::Mutex mutex;
+
+ 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);
+ }
+ mutex.unlock();
}
static class DebugInitFromEnv {
_______________________________________________
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