From: Chia-I Wu Date: Wed, 20 Aug 2014 06:40:28 +0000 (+0800) Subject: glsl: protect anonymous struct id with a mutex X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a6706163cb539fdb1f0432795d5c24b3e38f5cd7;p=mesa.git glsl: protect anonymous struct id with a mutex There may be two contexts compiling shaders at the same time, and we want the anonymous struct id to be globally unique. Signed-off-by: Chia-I Wu Reviewed-by: Brian Paul Reviewed-by: Ian Romanick --- diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp index 79f849465c3..27e3301e209 100644 --- a/src/glsl/glsl_parser_extras.cpp +++ b/src/glsl/glsl_parser_extras.cpp @@ -1350,9 +1350,15 @@ ast_struct_specifier::ast_struct_specifier(const char *identifier, ast_declarator_list *declarator_list) { if (identifier == NULL) { + static mtx_t mutex = _MTX_INITIALIZER_NP; static unsigned anon_count = 1; - identifier = ralloc_asprintf(this, "#anon_struct_%04x", anon_count); - anon_count++; + unsigned count; + + mtx_lock(&mutex); + count = anon_count++; + mtx_unlock(&mutex); + + identifier = ralloc_asprintf(this, "#anon_struct_%04x", count); } name = identifier; this->declarations.push_degenerate_list_at_head(&declarator_list->link);