[PATCH] Change base mutex implementations to use STL-provided mutexes

Zachary Turner zturner at google.com
Fri Jun 6 18:04:21 PDT 2014


On Fri, Jun 6, 2014 at 5:46 PM, Alp Toker <alp at nuanti.com> wrote:

>
> On 07/06/2014 02:34, Zachary Turner wrote:
>
>> Remove the Mutex.h dependency on windows.h, and address various other
>> review comments.
>>
>> This solution is still less than ideal, because we need to include some
>> windows preprocessor checks inside of Mutex.h.
>>
>
> It seems you could just have CriticalSectionMutex implemented as a
> standard Mutex when building on Unix.
>
> That way you don't need any preprocessor conditionals in either the header
> definition or at the point of use, and the fallback on non-Windows
> platforms is seamless.

But a Critical Section is not a thing that exists on Unix.  Isn't it a
little strange to have a name referring to something that only exists on
one platform just for convenience?



>
>
>  The best solution in my opinion would require allowing some platform
>> specific headers to be in the include tree  (for example,
>> include\llvm\Support\Windows\CriticalSectionMutex.h).  This would remove
>> all of the preprocessor code from Mutex.h, and allow anyone who needs this
>> to simply write #include "llvm/Support/Windows/CriticalSectionMutex.h".
>>
>
> We have actual clients we need to support that break with windows.h due to
> stomping on global namespaces and definitions -- conflicts are a likely
> scenario with any non-trivial piece of code that wasn't written to target
> Windows originally.
>
> The elegant and efficient solutions are all around if you take a look, but
> exposing windows.h isn't one of them.


Actually the solution I described there does not require exposing windows.h
through a header.  I understand that is frought with peril, and although I
do think we can (and should) eventually try to achieve that, I also
understand that it is difficult, requires care, and is outside the scope of
this CL.

Instead, what I'm saying is that we could simply expose some platform
specific headers to people outside of LLVM.   These headers themselves
would not include platform specific headers, they would only expose opaque
classes that deal with platform specific functionality.  For example, this
"include\Support\Windows\CriticalSectionMutex.h" would just have a void*
member, and lib\Support\Windows\CriticalSectionMutex.cpp would implement
it.  then libclang could #include "Support\Windows\CriticalSectionMutex.h"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140606/8896cc50/attachment.html>


More information about the llvm-commits mailing list