在 2025-10-1 20:28, Martin Storsjö 写道:
The previous form could cause the inner loop with YieldProcessor to
only read a cached stale value. Therefore, just iterate
YieldProcessor with InterlockedExchangePointer for attempting to
update the value.

Signed-off-by: Martin Storsjö <[email protected]>
---
  mingw-w64-libraries/winpthreads/src/spinlock.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/src/spinlock.c 
b/mingw-w64-libraries/winpthreads/src/spinlock.c
index 6e094d5ff..5dca17502 100644
--- a/mingw-w64-libraries/winpthreads/src/spinlock.c
+++ b/mingw-w64-libraries/winpthreads/src/spinlock.c
@@ -59,9 +59,7 @@ pthread_spin_lock (pthread_spinlock_t *lock)
  {
    volatile spinlock_word_t *lk = (volatile spinlock_word_t *)lock;
    while (unlikely(InterlockedExchangePointer((PVOID volatile *)lk, 0) == 0))
-    do {
-      YieldProcessor();
-    } while (*lk == 0);
+    YieldProcessor();
    return 0;
  }

LGTM.


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

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

Reply via email to