[Mesa-dev] [PATCH 1/2] c11/threads: add missing brackets around _MTX_INITIALIZER_NP

Roland Scheidegger sroland at vmware.com
Mon Aug 4 10:23:33 PDT 2014


Am 02.08.2014 03:51, schrieb Emil Velikov:
> On 02/08/14 00:26, Ian Romanick wrote:
>> On 08/01/2014 09:41 AM, Emil Velikov wrote:
>>> ... for win32 builds. Spotted this warning when I've imported the
>>> library into waffle, and gave mingw-w64-gcc a bash at compiling it.
>>>
>>> src/waffle/core/wcore_display.c:37:5: warning: missing braces around
>>> initializer [-Wmissing-braces]
>>> static mtx_t mutex = _MTX_INITIALIZER_NP;
>>> ^
>>>
>>> Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
>>> ---
>>>  include/c11/threads_win32.h | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/include/c11/threads_win32.h b/include/c11/threads_win32.h
>>> index 5298a84..35880ba 100644
>>> --- a/include/c11/threads_win32.h
>>> +++ b/include/c11/threads_win32.h
>>> @@ -85,7 +85,7 @@ Configuration macro:
>>>  #define TSS_DTOR_ITERATIONS 1
>>>  
>>>  // FIXME: temporary non-standard hack to ease transition
>>> -#define _MTX_INITIALIZER_NP {(PCRITICAL_SECTION_DEBUG)-1, -1, 0, 0, 0, 0}
>>> +#define _MTX_INITIALIZER_NP {{(PCRITICAL_SECTION_DEBUG)-1, -1, 0, 0, 0, 0}}
>>
>> This is because CRITICAL_SECTION is actually a typedef of a pointer to
>> some structure type, so it needs to be initialized like an array of
>> strcutres.  Yeah?
>>
> I wish I could agree.
> 
> CRITICAL_SECTION is a typedef of a typedef'ed struct (no pointers yet) where
> the first member is a struct *, as seen below.
> 
> typedef B CRITICAL_SECTION;
> typedef struct A {
>    struct *bla;
>    ...
> } B;
> 
> I remember spending a few hours reading and experimenting with this and every
> way I looked at it current code seems sane. In the end I've smashed the
> brackets not to pollute the build log and carried on with other stuff :) Don't
> think I have checked if MSVC complained about the issue though. Will give it a
> try next time I reboot.
> 
> 
>> I searched a bit on the net, and I could not find a single example of
>> initializing a win32 CRITICAL_SECTION this way.  Is this a good idea?
>> The FIXME comment doesn't inspire confidence...
>>
> Same here. AFAICS one should init the "mutex" via InitializeCriticalSection or
> InitializeCriticalSectionAndSpinCount. Either of which is very Win32 specific
> and not at all portable. Perhaps Jose (the author) can share some more
> insights on the topic ?
> 
> 
Yeah that seems fairly hacky. The idea is explained here (near the
beginning): http://locklessinc.com/articles/pthreads_on_windows/ -
according to the comments it doesn't work on windows xp even.

Roland




More information about the mesa-dev mailing list