Mesa (main): util/log: Add support for logging once.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Apr 6 00:37:10 UTC 2022
Module: Mesa
Branch: main
Commit: 04cdd41fdca073f1e225522921a252836654cd3c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=04cdd41fdca073f1e225522921a252836654cd3c
Author: Emma Anholt <emma at anholt.net>
Date: Fri Feb 18 10:49:24 2022 -0800
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 <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14999>
---
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;
More information about the mesa-commit
mailing list