[1/2] Fixed pthread_spin_lock on sparc32/64 (bug 16882)
Commit Message
From: GUO Yixuan <culu.gyx@gmail.com>
The bug occurs under this situation.
1. thread1 gets the lock, set the byte to FF
2. when thread2 is trying to lock, it enters the loop,
checking whether the byte is 00
3. thread1 unlocks, set to 00
4. thread2 finally gets the lock, without setting to FF
5. thread3 gets the lock, before thread2 unlocks it
---
nptl/sysdeps/sparc/sparc32/pthread_spin_lock.S | 4 ++--
nptl/sysdeps/sparc/sparc64/pthread_spin_lock.S | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
@@ -19,11 +19,11 @@
.text
ENTRY(pthread_spin_lock)
- ldstub [%o0], %g1
+1: ldstub [%o0], %g1
orcc %g1, 0x0, %g0
bne,a 2f
ldub [%o0], %g1
-1: retl
+ retl
mov 0, %o0
2: orcc %g1, 0x0, %g0
bne,a 2b
@@ -19,10 +19,10 @@
.text
ENTRY(pthread_spin_lock)
- ldstub [%o0], %g1
+1: ldstub [%o0], %g1
brnz,pn %g1, 2f
membar #StoreLoad | #StoreStore
-1: retl
+ retl
mov 0, %o0
2: ldub [%o0], %g1
brnz,pt %g1, 2b