Hello all,

At the risk of flooding a bit the list, I'm submitting the v4 of this
patch series.

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.
Best regards,

Changes from v3:

Return to using __stdcall instead of the WINAPI macro, which requires
including <windows.h>. It would have been required in pthread.h
otherwise.
Move all __declspec(dllimport) or __declspec(dllexport) specifiers
_before_ the return type, as explicitely recommended by the
documentation. MSVC doesn't support these specifiers after a pointer
star.

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 (9):
  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: Move __declspec specifiers before types

 .../winpthreads/include/pthread.h             | 244 +++++++++---------
 .../winpthreads/include/pthread_time.h        |  10 +-
 .../winpthreads/include/sched.h               |  10 +-
 .../winpthreads/include/semaphore.h           |  22 +-
 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 +-
 .../winpthreads/src/winpthread_internal.h     |   2 +-
 11 files changed, 208 insertions(+), 215 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