From 04cdd41fdca073f1e225522921a252836654cd3c Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Fri, 18 Feb 2022 10:49:24 -0800 Subject: [PATCH] util/log: Add support for logging once. These are not data-race safe (like many other once patterns in Mesa), so they might not log exactly once, but it should be good enough for not spamming the console. Reviewed-by: Dave Airlie Part-of: --- src/util/log.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util/log.h b/src/util/log.h index ccd00d627c0..d9e965a2bf6 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -68,6 +68,21 @@ mesa_log_v(enum mesa_log_level, const char *tag, const char *format, #define mesa_logd_v(fmt, va) __mesa_log_use_args((fmt), (va)) #endif +#define mesa_log_once(level, fmt, ...) \ + do \ + { \ + static bool once; \ + if (!once) { \ + once = true; \ + mesa_log(level, (MESA_LOG_TAG), fmt, ##__VA_ARGS__); \ + } \ + } while (0) + +#define mesa_loge_once(fmt, ...) mesa_log_once(MESA_LOG_ERROR, fmt, ##__VA_ARGS__) +#define mesa_logw_once(fmt, ...) mesa_log_once(MESA_LOG_WARN, fmt, ##__VA_ARGS__) +#define mesa_logi_once(fmt, ...) mesa_log_once(MESA_LOG_INFO, fmt, ##__VA_ARGS__) +#define mesa_logd_once(fmt, ...) mesa_log_once(MESA_LOG_DEBUG, fmt, ##__VA_ARGS__) + struct log_stream { char *msg; const char *tag;