util: Fixes os_get_option_cached with bool options_tbl_exited
authorYonggang Luo <luoyonggang@gmail.com>
Mon, 19 Dec 2022 16:29:10 +0000 (00:29 +0800)
committerMarge Bot <emma+marge@anholt.net>
Tue, 20 Dec 2022 01:49:10 +0000 (01:49 +0000)
Fixes: cdad035cfd9 ("util: Add function debug_get_option_cached os_get_option_cached")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7922

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20386>

src/util/os_misc.c

index a10c608..538b3f6 100644 (file)
@@ -186,6 +186,7 @@ os_get_option(const char *name)
 }
 
 static struct hash_table *options_tbl;
+static bool options_tbl_exited = false;
 static simple_mtx_t options_tbl_mtx = SIMPLE_MTX_INITIALIZER;
 
 /**
@@ -195,14 +196,23 @@ static simple_mtx_t options_tbl_mtx = SIMPLE_MTX_INITIALIZER;
 static void
 options_tbl_fini(void)
 {
+   simple_mtx_lock(&options_tbl_mtx);
    _mesa_hash_table_destroy(options_tbl, NULL);
+   options_tbl = NULL;
+   options_tbl_exited = true;
+   simple_mtx_unlock(&options_tbl_mtx);
 }
 
 const char *
 os_get_option_cached(const char *name)
 {
-   char *opt = NULL;
+   const char *opt = NULL;
    simple_mtx_lock(&options_tbl_mtx);
+   if (options_tbl_exited) {
+      opt = os_get_option(name);
+      goto exit_mutex;
+   }
+
    if (!options_tbl) {
       options_tbl = _mesa_hash_table_create(NULL, _mesa_hash_string,
             _mesa_key_string_equal);