Mesa (main): util/u_debug: Use 'initialized' instead of 'first'
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jun 10 07:30:09 UTC 2022
Module: Mesa
Branch: main
Commit: 279f32e042c3ef9bc4311fd802ecebba61cb17a7
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=279f32e042c3ef9bc4311fd802ecebba61cb17a7
Author: Kristian H. Kristensen <hoegsberg at google.com>
Date: Thu Jun 9 14:11:44 2022 -0400
util/u_debug: Use 'initialized' instead of 'first'
Using 'initialized' to guard the one-time init, means it can be set to
false as part of .bss instead setting 'first' to true in .data. This
is more efficient and works at .ctor time.
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Reviewed-by: Emma Anholt <emma at anholt.net>
Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16952>
---
src/util/u_debug.c | 6 +++---
src/util/u_debug.h | 30 +++++++++++++++---------------
src/util/u_debug_stack.c | 6 +++---
3 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/src/util/u_debug.c b/src/util/u_debug.c
index e5101bf431a..6fda1fdcf85 100644
--- a/src/util/u_debug.c
+++ b/src/util/u_debug.c
@@ -121,16 +121,16 @@ debug_print_blob(const char *name, const void *blob, unsigned size)
static bool
debug_get_option_should_print(void)
{
- static bool first = true;
+ static bool initialized = false;
static bool value = false;
- if (!first)
+ if (initialized)
return value;
/* Oh hey this will call into this function,
* but its cool since we set first to false
*/
- first = false;
+ initialized = true;
value = debug_get_bool_option("GALLIUM_PRINT_OPTIONS", false);
/* XXX should we print this option? Currently it wont */
return value;
diff --git a/src/util/u_debug.h b/src/util/u_debug.h
index 4986bee112b..b5d9a505cfb 100644
--- a/src/util/u_debug.h
+++ b/src/util/u_debug.h
@@ -449,10 +449,10 @@ debug_get_flags_option(const char *name,
static const char * \
debug_get_option_ ## suffix (void) \
{ \
- static bool first = true; \
+ static bool initialized = false; \
static const char * value; \
- if (first) { \
- first = false; \
+ if (!initialized) { \
+ initialized = true; \
value = debug_get_option(name, dfault); \
} \
return value; \
@@ -478,12 +478,12 @@ __check_suid(void)
static FILE * \
debug_get_option_ ## suffix (void) \
{ \
- static bool first = true; \
+ static bool initialized = false; \
static const char * value; \
if (__check_suid()) \
return NULL; \
- if (first) { \
- first = false; \
+ if (!initialized) { \
+ initialized = true; \
value = debug_get_option(name, dfault); \
} \
if (!value) \
@@ -495,10 +495,10 @@ debug_get_option_ ## suffix (void) \
static bool \
debug_get_option_ ## sufix (void) \
{ \
- static bool first = true; \
+ static bool initialized = false; \
static bool value; \
- if (first) { \
- first = false; \
+ if (!initialized) { \
+ initialized = true; \
value = debug_get_bool_option(name, dfault); \
} \
return value; \
@@ -508,10 +508,10 @@ debug_get_option_ ## sufix (void) \
static long \
debug_get_option_ ## sufix (void) \
{ \
- static bool first = true; \
+ static bool initialized = false; \
static long value; \
- if (first) { \
- first = false; \
+ if (!initialized) { \
+ initialized = true; \
value = debug_get_num_option(name, dfault); \
} \
return value; \
@@ -521,10 +521,10 @@ debug_get_option_ ## sufix (void) \
static unsigned long \
debug_get_option_ ## sufix (void) \
{ \
- static bool first = true; \
+ static bool initialized = false; \
static unsigned long value; \
- if (first) { \
- first = false; \
+ if (!initialized) { \
+ initialized = true; \
value = debug_get_flags_option(name, flags, dfault); \
} \
return value; \
diff --git a/src/util/u_debug_stack.c b/src/util/u_debug_stack.c
index a0d9499d46b..12fc7dc809a 100644
--- a/src/util/u_debug_stack.c
+++ b/src/util/u_debug_stack.c
@@ -301,11 +301,11 @@ static mtx_t backtrace_mutex;
static void
initialize_backtrace_mutex()
{
- static bool first = true;
+ static bool initialized = false;
- if (first) {
+ if (!initialized) {
(void)mtx_init(&backtrace_mutex, mtx_plain);
- first = false;
+ initialized = true;
}
}
More information about the mesa-commit
mailing list