[Mesa-dev] [PATCH 1/2] util: add debug_warn_once() macro

Brian Paul brianp at vmware.com
Thu Jan 5 14:19:45 PST 2012


Emits a warning message, but only once to avoid tons of repeated warnings.
---
 src/gallium/auxiliary/util/u_debug.h |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h
index cbea358..ed19cda 100644
--- a/src/gallium/auxiliary/util/u_debug.h
+++ b/src/gallium/auxiliary/util/u_debug.h
@@ -215,6 +215,25 @@ void _debug_assert_fail(const char *expr,
 
 
 /**
+ * Emit a warning message, but only once.
+ */
+#ifdef DEBUG
+#define debug_warn_once(__msg) \
+   do { \
+      static bool warned = FALSE; \
+      if (!warned) { \
+         _debug_printf("%s:%u:%s: one time warning: %s\n", \
+                       __FILE__, __LINE__, __FUNCTION__, __msg); \
+         warned = TRUE; \
+      } \
+   } while (0)
+#else
+#define debug_warn_once(__msg) \
+   ((void)0) 
+#endif
+
+
+/**
  * Output an error message. Not muted on release version.
  */
 #ifdef DEBUG
-- 
1.7.3.4



More information about the mesa-dev mailing list