shithub: mc

Download patch

ref: 5197866beb5ead9160183b6ada7a76244686f9f8
parent: a4fdef8a867263627510ea20e9b4a758549f7c98
author: iriri <[email protected]>
date: Sat Mar 16 16:05:12 EDT 2019

Add synchronization to xset.

Unfortunately, this is necessary to achieve sequential consistency.

--- a/lib/thread/atomic-impl+plan9-x64.s
+++ b/lib/thread/atomic-impl+plan9-x64.s
@@ -14,16 +14,16 @@
 
 // set variants
 TEXT thread$xset8+0(SB),1,$0
-	MOVB	SI, (DI)
+	LOCK; XCHGB	(DI), SI
 	RET
 TEXT thread$xset32+0(SB),1,$0
-	MOVL	SI, (DI)
+	LOCK; XCHGL	(DI), SI
 	RET
 TEXT thread$xset64+0(SB),1,$0
-	MOVQ	SI, (DI)
+	LOCK; XCHGQ	(DI), SI
 	RET
 TEXT thread$xsetp+0(SB),1,$0
-	MOVQ	SI, (DI)
+	LOCK; XCHGQ	(DI), SI
 	RET
 
 // add variants
--- a/lib/thread/atomic-impl+x64.s
+++ b/lib/thread/atomic-impl+x64.s
@@ -27,13 +27,13 @@
 .globl _thread$xset8
 thread$xset8:
 _thread$xset8:
-	movl	%esi, (%rdi)
+	lock xchgb	(%rdi), %sil
 	ret
 .globl thread$xset32
 .globl _thread$xset32
 thread$xset32:
 _thread$xset32:
-	movl	%esi, (%rdi)
+	lock xchgl	(%rdi), %esi
 	ret
 .globl thread$xset64
 .globl thread$xsetp
@@ -43,7 +43,7 @@
 thread$xsetp:
 _thread$xset64:
 _thread$xsetp:
-	movq	%rsi, (%rdi)
+	lock xchgq	(%rdi), %rsi
 	ret
 
 # add variants