[vlc-commits] commit: Only print the first 5 threading errors each ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Mon Jun 7 19:51:26 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jun  7 20:42:49 2010 +0300| [2dde53c525ed5c9a8d74bb8a85e3ea8ead1dcd11] | committer: Rémi Denis-Courmont 

Only print the first 5 threading errors each

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2dde53c525ed5c9a8d74bb8a85e3ea8ead1dcd11
---

 bin/override.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/bin/override.c b/bin/override.c
index b5de22d..2385f2b 100644
--- a/bin/override.c
+++ b/bin/override.c
@@ -23,6 +23,7 @@
 #endif
 
 #include <stdbool.h>
+#define MAX_ERRORS 5
 
 void vlc_enable_override (void);
 
@@ -56,32 +57,37 @@ void vlc_enable_override (void)
     pthread_atfork (NULL, NULL, vlc_reset_override);
 }
 
-static void vlogbug (const char *level, const char *func, const char *fmt,
-                     va_list ap)
+static void vlogbug (unsigned *pc, const char *level, const char *func,
+                     const char *fmt, va_list ap)
 {
 #ifdef HAVE_BACKTRACE
-    const size_t framec = 4;
+    const size_t framec = 5;
     void *framev[framec];
 
     backtrace (framev, framec);
 #endif
     flockfile (stderr);
-    fprintf (stderr, "%s: call to %s(", level, func);
-    vfprintf (stderr, fmt, ap);
-    fputs (")\n", stderr);
-    fflush (stderr);
+    if (*pc < MAX_ERRORS)
+    {
+        (*pc)++;
+        fprintf (stderr, "%s: call to %s(", level, func);
+        vfprintf (stderr, fmt, ap);
+        fputs (")\n", stderr);
+        fflush (stderr);
 #ifdef HAVE_BACKTRACE
-    backtrace_symbols_fd (framev + 2, framec - 2, fileno (stderr));
+        backtrace_symbols_fd (framev + 2, framec - 2, fileno (stderr));
 #endif
+    }
     funlockfile (stderr);
 }
 
-static void logbug (const char *level, const char *func, const char *fmt, ...)
+static void logbug (unsigned *pc, const char *level, const char *func,
+                    const char *fmt, ...)
 {
     va_list ap;
 
     va_start (ap, fmt);
-    vlogbug (level, func, fmt, ap);
+    vlogbug (pc, level, func, fmt, ap);
     va_end (ap);
 }
 
@@ -97,7 +103,12 @@ static void *getsym (const char *name)
     return sym;
 }
 
-#define LOG(level, ...) logbug(level, __func__, __VA_ARGS__)
+#define LOG(level, ...) \
+    do { \
+        static unsigned counter = 0; \
+        logbug(&counter, level, __func__, __VA_ARGS__); \
+    } while (0)
+
 /* Evil non-standard GNU C macro ;)
  *  typeof keyword,
  *  statement-expression,



More information about the vlc-commits mailing list