[Mesa-dev] [PATCH 03/21] glsl: protect anonymous struct id with a mutex

Matt Turner mattst88 at gmail.com
Sun May 4 15:43:27 PDT 2014


On Fri, May 2, 2014 at 10:33 AM, Ian Romanick <idr at freedesktop.org> wrote:
> On 04/22/2014 01:58 AM, Chia-I Wu wrote:
>> There may be two contexts compiling shaders at the same time, and we want the
>> anonymous struct id to be globally unique.
>
> I am not very excited about this.
>
> Is there any chance of getting stdatomic.h for the MSVC compilers that
> people care about?  I'd much rather have this code be...
>
>    if (identifier == NULL) {
>       static volatile atomic_uint_t anon_count = ATOMIC_VAR_INIT(1);
>       unsigned count;
>
>       count = atomic_fetch_add(&anon_count, 1);
>       identifier = ralloc_asprintf(this, "#anon_struct_%04x", count);
>    }

Note that gcc-4.9 is the first version to have stdatomic.h.

gcc has supported atomic built-ins for a long time though:
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html


More information about the mesa-dev mailing list