This is an archive of the discontinued LLVM Phabricator instance.

Build thread_win32.cpp only if LIBCXX_HAS_PTHREAD_API is not set.
ClosedPublic

Authored by ColinFinck on Feb 9 2021, 6:40 AM.

Details

Summary

This allows building libc++ against winpthreads from mingw-w64 to support operating systems older than Windows 7.
The remaining libc++ code already supports WIN32 with LIBCXX_HAS_PTHREAD_API.

Note that there is also the older "pthreads-win32". However, that support library implements pthread_t as a struct, which violates the libc++ assumption that pthread_t is always a scalar and can be compared, ordered, and set to zero.

Diff Detail

Event Timeline

ColinFinck created this revision.Feb 9 2021, 6:40 AM
ColinFinck requested review of this revision.Feb 9 2021, 6:40 AM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptFeb 9 2021, 6:40 AM

The change looks fine to me (although I didn't try it myself - and with the additional request to add another condition to it), but someone else has to approve it as well. Can you provide your desired git author string (Full Name <email@domain>) to be used when it would be applied?

libcxx/src/CMakeLists.txt
82

This is the cmake define for when pthread api is explicitly forced to be used, instead of autodetection based on platform and __has_include(<pthread.h>) and such - right? In that case I guess it's ok.

There's also been a desire (in https://reviews.llvm.org/D88124#change-1LdJXjC8YEPj) to make compilation of this file optional based on LIBCXX_ENABLE_THREADS - I guess it'd be nice to do that at the same time while adding conditionals here.

Colin Finck <colin@reactos.org>

ldionne accepted this revision.Feb 16 2021, 7:02 AM
ldionne added a subscriber: ldionne.
ldionne added inline comments.
libcxx/src/CMakeLists.txt
82

Actually, it's impossible for LIBCXX_HAS_PTHREAD_API to be set to ON if LIBCXX_ENABLE_THREADS is OFF, so I think this is OK as-is.

This revision is now accepted and ready to land.Feb 16 2021, 7:02 AM
mstorsjo added inline comments.Feb 16 2021, 8:36 AM
libcxx/src/CMakeLists.txt
82

I meant for the configuration with LIBCXX_HAS_PTHREAD_API disabled and LIBCXX_ENABLE_THREADS disabled too - in that case we still compile thread_win32.cpp (just as before this change). Not sure if there is an issue with such a config or not though - if such a patch is submitted (split out from D88124), I guess it would come with an explanation of exactly what issue it fixes.