ref: 28c95a0761154c121b49e54912f0c45dc7dffec0
parent: 77c74d43d5540fd3bb3915d45d786986827ef0f8
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Sep 16 05:32:19 EDT 2015
Add more atomics for pointer-sized things.
--- a/lib/thread/atomic-impl+x64.s
+++ b/lib/thread/atomic-impl+x64.s
@@ -3,7 +3,9 @@
movl (%rdi), %eax
ret
.globl thread$xget64
+.globl thread$xgetp
thread$xget64:
+thread$xgetp:
movq (%rdi), %rax
ret
.globl thread$xset32
@@ -11,7 +13,9 @@
movl %esi, (%rdi)
ret
.globl thread$xset64
+.globl thread$xsetp
thread$xset64:
+thread$xsetp:
movq %rsi, (%rdi)
ret
.globl thread$xadd32
@@ -19,7 +23,9 @@
lock xaddl %esi, (%rdi)
ret
.globl thread$xadd64
+.globl thread$xaddp
thread$xadd64:
+thread$xaddp:
lock xaddq %rsi, (%rdi)
ret
.globl thread$xsub32
@@ -27,7 +33,9 @@
lock xaddl %esi, (%rdi)
ret
.globl thread$xsub64
+.globl thread$xsubp
thread$xsub64:
+thread$xsubp:
lock xaddq %rsi, (%rdi)
ret
.globl thread$xcas32
@@ -36,7 +44,9 @@
lock cmpxchgl %edx, (%rdi)
ret
.globl thread$xcas64
+.globl thread$xcasp
thread$xcas64:
+thread$xcasp:
movq %rsi, %rax
lock cmpxchgq %rdx, (%rdi)
ret
@@ -46,7 +56,9 @@
lock xchgl (%rdi), %eax
ret
.globl thread$xchg64
+.globl thread$xchgp
thread$xchg64:
+thread$xchgp:
movq %rsi, %rax
lock xchgq (%rdi), %rax
ret
--- a/lib/thread/atomic.myr
+++ b/lib/thread/atomic.myr
@@ -54,20 +54,35 @@
xchg = {p, v; -> xchg64(p, v)}
;;
+impl atomic std.intptr =
+ xget = {p; -> xgetp(p)}
+ xset = {p, v; xsetp(p, v)}
+ xadd = {p, v; -> xaddp(p, v)}
+ xsub = {p, v; -> xsubp(p, v)}
+ xcas = {p, old, new; -> xcasp(p, old, new)}
+ xchg = {p, v; -> xchgp(p, v)}
+;;
+
extern const xget32 : (p : uint32# -> uint32)
extern const xget64 : (p : uint64# -> uint64)
+extern const xgetp : (p : std.intptr# -> std.intptr)
extern const xset32 : (p : uint32#, v : uint32 -> void)
extern const xset64 : (p : uint64#, v : uint64 -> void)
+extern const xsetp : (p : std.intptr#, v : std.intptr -> void)
extern const xadd32 : (p : uint32#, v : uint32 -> uint32)
extern const xadd64 : (p : uint64#, v : uint64 -> uint64)
+extern const xaddp : (p : std.intptr#, v : std.intptr -> std.intptr)
extern const xsub32 : (p : uint32#, v : uint32 -> uint32)
extern const xsub64 : (p : uint64#, v : uint64 -> uint64)
+extern const xsubp : (p : std.intptr#, v : std.intptr -> std.intptr)
extern const xcas32 : (p : uint32#, old: uint32, new : uint32 -> uint32)
extern const xcas64 : (p : uint64#, old: uint64, new : uint64 -> uint64)
+extern const xcasp : (p : std.intptr#, old: std.intptr, new : std.intptr -> std.intptr)
extern const xchg32 : (p : uint32#, v : uint32 -> uint32)
extern const xchg64 : (p : uint64#, v : uint64 -> uint64)
+extern const xchgp : (p : std.intptr#, v : std.intptr -> std.intptr)
--- a/lib/thread/mutex+linux.myr
+++ b/lib/thread/mutex+linux.myr
@@ -52,8 +52,6 @@
}
const mtxunlock = {mtx
- var r
-
/* uncontended sleep means we can just unlock and move on */
if mtx._state == Sleep
mtx._state = Unlocked
@@ -71,8 +69,7 @@
relax()
;;
- r = sys.futex(&mtx._state, sys.Futexwake | sys.Futexpriv, Locked, Zptr, Zptr, 0)
-
+ sys.futex(&mtx._state, sys.Futexwake | sys.Futexpriv, 1, Zptr, Zptr, 0)
}
const relax = {