mesa: Synchronize get_gl_override()
authorRob Clark <robdclark@chromium.org>
Tue, 17 Nov 2020 22:40:24 +0000 (14:40 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 24 Nov 2020 21:03:34 +0000 (21:03 +0000)
Fixes helgrind complaint found with piglit glx-multithread-clearbuffer.
This is a legit race because override[api].version is cleared before
parsing the override string.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7644>

src/mesa/main/version.c

index 418d20e..2056d07 100644 (file)
 #include <stdio.h>
 #include "context.h"
 
+#include "util/simple_mtx.h"
+
 #include "mtypes.h"
 #include "version.h"
 #include "git_sha1.h"
 
+static simple_mtx_t override_lock = _SIMPLE_MTX_INITIALIZER_NP;
+
 /**
  * Scans 'string' to see if it ends with 'ending'.
  */
@@ -72,6 +76,8 @@ get_gl_override(gl_api api, int *version, bool *fwd_context,
 
    STATIC_ASSERT(ARRAY_SIZE(override) == API_OPENGL_LAST + 1);
 
+   simple_mtx_lock(&override_lock);
+
    if (api == API_OPENGLES)
       goto exit;
 
@@ -108,6 +114,8 @@ exit:
    *version = override[api].version;
    *fwd_context = override[api].fc_suffix;
    *compat_context = override[api].compat_suffix;
+
+   simple_mtx_unlock(&override_lock);
 }
 
 /**