glsl: protect anonymous struct id with a mutex
authorChia-I Wu <olvaffe@gmail.com>
Wed, 20 Aug 2014 06:40:28 +0000 (14:40 +0800)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 30 Oct 2014 09:26:19 +0000 (02:26 -0700)
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 <olv@lunarg.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/glsl_parser_extras.cpp

index 79f849465c3211e0f4c6cbda947a40c1467d01ef..27e3301e2093636d6c5818770d3fc2aef8c8ff65 100644 (file)
@@ -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);