This patch series enables building winpthreads with MSVC. The missing
steps were about removing uses of GCC extensions, in favor of using
functions already provided by windows.h. MinGW also provides these
functions, so there should be no need for redefinitions in
winpthreads.

If there's interest, further work could switch to C11 atomics [1]
instead of Windows Interlocked Variable Access [2] and WinAPI memory
barriers that I've used to replace GCC old __sync extensions [3].
GCC introduced support for C11 atomics in 4.9, and MSVC recently
introduced partial, but sufficient support for C11 atomics [4].

[1]: https://en.cppreference.com/w/c/atomic
[2]: 
https://learn.microsoft.com/en-us/windows/win32/sync/interlocked-variable-access
[3]: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html
[4]: 
https://devblogs.microsoft.com/cppblog/c11-atomics-in-visual-studio-2022-version-17-5-preview-2/

Thanks to Martin Storsjö and LIU Hao for reviewing this patch series.

Changes from v2:

Protect symbols that may be exposed if winpthreads is build as a
static library by putting them in the '_pthread_' namespace.
Improve commit messages.

Changes from v1:

Improves how winpthreads uses recent WinAPI functions (e.g.,
GetTickCount64) and respects the current way of loading theses
functions at runtime with GetModuleHandle and GetProcAddress. It uses
a function tagged with the constructor attribute for MinGW and
clang-cl, and a CRT initialization and linker trick to use a single
'winpthreads_init' function to load these required WinAPI functions.

Antonin Décimo (8):
  winpthreads: Check if requested stack size fits in an unsigned int
  winpthreads: Fix pthread_create_wrapper type
  winpthreads: Use YieldProcessor in pthread_spin_lock
  winpthreads: Replace GCC's __sync comparisons with WinAPI functions
  winpthreads: Don't use GCC __sync_synchronize
  winpthreads: Unify discovery of recent WinAPI functions
  winpthreads: Simplify placing a symbol in a section
  winpthreads: Use GetModuleHandleA to prevent Unicode errors

 .../winpthreads/include/pthread.h             |  6 +--
 mingw-w64-libraries/winpthreads/src/clock.c   | 31 ++-----------
 mingw-w64-libraries/winpthreads/src/misc.c    | 45 ++++++++++++++++---
 mingw-w64-libraries/winpthreads/src/misc.h    | 14 +-----
 mingw-w64-libraries/winpthreads/src/mutex.c   | 15 +++----
 .../winpthreads/src/spinlock.c                | 12 ++---
 mingw-w64-libraries/winpthreads/src/thread.c  | 18 +++++---
 7 files changed, 67 insertions(+), 74 deletions(-)

-- 
2.43.0



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to