summaryrefslogtreecommitdiff
path: root/lib/thread
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-16 09:32:19 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-16 09:32:19 -0700
commit28c95a0761154c121b49e54912f0c45dc7dffec0 (patch)
treed23938f65dd35b88bf4637ea8a982f70a23028b6 /lib/thread
parent77c74d43d5540fd3bb3915d45d786986827ef0f8 (diff)
downloadmc-28c95a0761154c121b49e54912f0c45dc7dffec0.tar.gz
Add more atomics for pointer-sized things.
Diffstat (limited to 'lib/thread')
-rw-r--r--lib/thread/atomic-impl+x64.s12
-rw-r--r--lib/thread/atomic.myr15
-rw-r--r--lib/thread/mutex+linux.myr5
3 files changed, 28 insertions, 4 deletions
diff --git a/lib/thread/atomic-impl+x64.s b/lib/thread/atomic-impl+x64.s
index 10f3281..8824ba2 100644
--- a/lib/thread/atomic-impl+x64.s
+++ b/lib/thread/atomic-impl+x64.s
@@ -3,7 +3,9 @@ thread$xget32:
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 @@ thread$xset32:
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 @@ thread$xadd32:
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 @@ thread$xsub32:
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 @@ thread$xcas32:
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 @@ thread$xchg32:
lock xchgl (%rdi), %eax
ret
.globl thread$xchg64
+.globl thread$xchgp
thread$xchg64:
+thread$xchgp:
movq %rsi, %rax
lock xchgq (%rdi), %rax
ret
diff --git a/lib/thread/atomic.myr b/lib/thread/atomic.myr
index 625c047..a842b88 100644
--- a/lib/thread/atomic.myr
+++ b/lib/thread/atomic.myr
@@ -54,20 +54,35 @@ impl atomic uint64 =
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)
diff --git a/lib/thread/mutex+linux.myr b/lib/thread/mutex+linux.myr
index 3edb48a..dc5175b 100644
--- a/lib/thread/mutex+linux.myr
+++ b/lib/thread/mutex+linux.myr
@@ -52,8 +52,6 @@ const mtxtrylock = {mtx
}
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 @@ const mtxunlock = {mtx
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 = {