diff options
author | Chia-I Wu <olvaffe@gmail.com> | 2014-08-20 14:40:29 +0800 |
---|---|---|
committer | Kenneth Graunke <kenneth@whitecape.org> | 2014-10-30 02:26:19 -0700 |
commit | 2d64e4ffbab0426317f329e2bae22566dc80b98a (patch) | |
tree | fa74541ce0082e0842311a917327eeb06aa898ab /src/glsl/glsl_types.h | |
parent | a6706163cb539fdb1f0432795d5c24b3e38f5cd7 (diff) | |
download | external_mesa3d-2d64e4ffbab0426317f329e2bae22566dc80b98a.zip external_mesa3d-2d64e4ffbab0426317f329e2bae22566dc80b98a.tar.gz external_mesa3d-2d64e4ffbab0426317f329e2bae22566dc80b98a.tar.bz2 |
glsl: protect glsl_type with a mutex
glsl_type has several static hash tables and a static ralloc context. They
need to be protected by a mutex as they are not thread-safe.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=69200
Signed-off-by: Chia-I Wu <olv@lunarg.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Diffstat (limited to 'src/glsl/glsl_types.h')
-rw-r--r-- | src/glsl/glsl_types.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h index eeb14c2..6543041 100644 --- a/src/glsl/glsl_types.h +++ b/src/glsl/glsl_types.h @@ -122,16 +122,18 @@ struct glsl_type { * easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */ static void* operator new(size_t size) { - if (glsl_type::mem_ctx == NULL) { - glsl_type::mem_ctx = ralloc_context(NULL); - assert(glsl_type::mem_ctx != NULL); - } + mtx_lock(&glsl_type::mutex); + + /* mem_ctx should have been created by the static members */ + assert(glsl_type::mem_ctx != NULL); void *type; type = ralloc_size(glsl_type::mem_ctx, size); assert(type != NULL); + mtx_unlock(&glsl_type::mutex); + return type; } @@ -139,7 +141,9 @@ struct glsl_type { * ralloc_free in that case. */ static void operator delete(void *type) { + mtx_lock(&glsl_type::mutex); ralloc_free(type); + mtx_unlock(&glsl_type::mutex); } /** @@ -618,6 +622,9 @@ struct glsl_type { bool record_compare(const glsl_type *b) const; private: + + static mtx_t mutex; + /** * ralloc context for all glsl_type allocations * |