On Wed, 1 Oct 2025, LIU Hao wrote:

在 2025-10-1 20:34, Martin Storsjö 写道:
On GCC compatible compilers, use a store with release semantics;
this generates more efficient code than a full
InterlockedExchangePointer.

This avoids hangs in some cases, on aarch64.

Signed-off-by: Martin Storsjö <[email protected]>
---
  mingw-w64-libraries/winpthreads/src/spinlock.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mingw-w64-libraries/winpthreads/src/spinlock.c b/mingw-w64-libraries/winpthreads/src/spinlock.c
index eb21509d6..d5efe138f 100644
--- a/mingw-w64-libraries/winpthreads/src/spinlock.c
+++ b/mingw-w64-libraries/winpthreads/src/spinlock.c
@@ -77,6 +77,10 @@ int
  pthread_spin_unlock (pthread_spinlock_t *lock)
  {
    volatile spinlock_word_t *lk = (volatile spinlock_word_t *)lock;
-  *lk = -1;
+#if defined(__GNUC__) || defined(__clang__)
+  __atomic_store_n(lk, -1, __ATOMIC_RELEASE);
+#else
+  InterlockedExchangePointer((PVOID volatile *)lk, (void*)-1);
+#endif
    return 0;
  }

LGTM.

Thanks, pushed this one as well.

// Martin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to