diff options
author | Daniel Kurtz <djkurtz@chromium.org> | 2014-02-07 19:29:06 +0800 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2014-03-04 13:12:27 -0800 |
commit | 5f35078700b24cdead1e8f9372fdb14e748c05bc (patch) | |
tree | c1bd874cd7c28f417e15b79c71952f0d5fa3d24e | |
parent | aa1f7b42379b7574f06d0df2cee3e4d9f54e1ccf (diff) |
glsl: Add locking to builtin_builder singleton
Consider a multithreaded program with two contexts A and B, and the
following scenario:
1. Context A calls initialize(), which allocates mem_ctx and starts
building built-ins.
2. Context B calls initialize(), which sees mem_ctx != NULL and assumes
everything is already set up. It returns.
3. Context B calls find(), which fails to find the built-in since it
hasn't been created yet.
4. Context A finally finishes initializing the built-ins.
This will break at step 3. Adding a lock ensures that subsequent
callers of initialize() will wait until initialization is actually
complete.
Similarly, if any thread calls release while another thread is still
initializing, or calling find(), the mem_ctx/shader would get free'd while
from under it, leading to corruption or use-after-free crashes.
Fixes sporadic failures in Piglit's glx-multithread-shader-compile.
Bugzilla: https://bugs.freedesktop.org/69200
Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Cc: "10.1 10.0" <mesa-stable@lists.freedesktop.org>
(cherry picked from commit b47d231526821f5cff99546a984103a7222bc66c)
-rw-r--r-- | src/glsl/builtin_functions.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp index 22f2d6d1f2b..0f41babd7d9 100644 --- a/src/glsl/builtin_functions.cpp +++ b/src/glsl/builtin_functions.cpp @@ -3997,6 +3997,7 @@ builtin_builder::_atomic_op(const char *intrinsic, /* The singleton instance of builtin_builder. */ static builtin_builder builtins; +_glthread_DECLARE_STATIC_MUTEX(builtins_lock); /** * External API (exposing the built-in module to the rest of the compiler): @@ -4005,19 +4006,27 @@ static builtin_builder builtins; void _mesa_glsl_initialize_builtin_functions() { + _glthread_LOCK_MUTEX(builtins_lock); builtins.initialize(); + _glthread_UNLOCK_MUTEX(builtins_lock); } void _mesa_glsl_release_builtin_functions() { + _glthread_LOCK_MUTEX(builtins_lock); builtins.release(); + _glthread_UNLOCK_MUTEX(builtins_lock); } ir_function_signature * _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state, const char *name, exec_list *actual_parameters) { - return builtins.find(state, name, actual_parameters); + ir_function_signature * s; + _glthread_LOCK_MUTEX(builtins_lock); + s = builtins.find(state, name, actual_parameters); + _glthread_UNLOCK_MUTEX(builtins_lock); + return s; } /** @} */ |