summaryrefslogtreecommitdiff
path: root/lib/thread
diff options
context:
space:
mode:
authoririri <iri@konnichiwastevenspielbergde.su>2018-06-23 05:33:08 +0300
committerOri Bernstein <ori@eigenstate.org>2018-06-22 21:09:09 -0700
commit7b5b914cf702375f8f532c2fe43c04d6eacd1fd6 (patch)
treee962fdb493904604ae5b23c2ee64ab4c29a48df6 /lib/thread
parent7c2f25e309226a9506ea4b37e94e560017e83994 (diff)
downloadmc-7b5b914cf702375f8f532c2fe43c04d6eacd1fd6.tar.gz
Add ftxtag type and add missing casts
Diffstat (limited to 'lib/thread')
-rw-r--r--lib/thread/futex+freebsd.myr33
-rw-r--r--lib/thread/futex+linux.myr30
-rw-r--r--lib/thread/futex+openbsd:6.2.myr23
-rw-r--r--lib/thread/futex+osx.myr39
-rw-r--r--lib/thread/mutex+futex.myr2
-rw-r--r--lib/thread/sem+futex.myr4
6 files changed, 105 insertions, 26 deletions
diff --git a/lib/thread/futex+freebsd.myr b/lib/thread/futex+freebsd.myr
index 1ca52c7..3eb9ccb 100644
--- a/lib/thread/futex+freebsd.myr
+++ b/lib/thread/futex+freebsd.myr
@@ -3,8 +3,11 @@ use sys
use "common"
pkg thread =
- const ftxwait : (uaddr : uint64#, val : uint64, timeout : sys.timespec# -> int)
- const ftxwake : (uaddr : uint64# -> int)
+ type ftxtag = uint32
+ impl atomic ftxtag
+
+ const ftxwait : (uaddr : ftxtag#, val : ftxtag, timeout : sys.timespec# -> int)
+ const ftxwake : (uaddr : ftxtag# -> int)
;;
const ftxwait = {uaddr, val, timeout
@@ -13,13 +16,31 @@ const ftxwait = {uaddr, val, timeout
;;
var ut : sys._umtx_time = [
- ._timeout = timeout#
- ._flags = sys.Umtxabstime
- ._clockid = 1 /* CLOCK_MONOTONIC. Not exported from sys. */
+ ._timeout = timeout#,
+ ._flags = (sys.Umtxabstime : uint32),
+ ._clockid = 1, /* CLOCK_MONOTONIC. Not exported from sys. */
]
- -> sys.umtx_op((uaddr : void#), sys.Umtxwaituintpriv, (val : uint64), (sys.sizeof(sys._umtx_time) : void#), &ut)
+ -> sys.umtx_op((uaddr : void#),
+ sys.Umtxwaituintpriv,
+ (val : uint64),
+ (sys.sizeof(sys._umtx_time) : void#),
+ (&ut : void#))
}
const ftxwake = {uaddr
-> sys.umtx_op((uaddr : void#), sys.Umtxwakepriv, 1, Zptr, Zptr)
}
+
+impl atomic ftxtag =
+ xget = {p; -> (xget32((p : uint32#)) : ftxtag)}
+ xset = {p, v; xset32((p : uint32#), (v : uint32))}
+ xadd = {p, v; -> (xadd32((p : uint32#), (v : uint32)) : ftxtag)}
+ xcas = {p, old, new; -> (xcas32((p : uint32#), (old : uint32), (new : uint32)) : ftxtag)}
+ xchg = {p, v; -> (xchg32((p : uint32#), (v : uint32)) : ftxtag)}
+;;
+
+extern const xget32 : (p : uint32# -> uint32)
+extern const xset32 : (p : uint32#, v : uint32 -> void)
+extern const xadd32 : (p : uint32#, v : uint32 -> uint32)
+extern const xcas32 : (p : uint32#, old: uint32, new : uint32 -> uint32)
+extern const xchg32 : (p : uint32#, v : uint32 -> uint32)
diff --git a/lib/thread/futex+linux.myr b/lib/thread/futex+linux.myr
index e6cec24..39aabc3 100644
--- a/lib/thread/futex+linux.myr
+++ b/lib/thread/futex+linux.myr
@@ -3,14 +3,36 @@ use sys
use "common"
pkg thread =
- const ftxwait : (uaddr : uint64#, val : uint64, timeout : sys.timespec# -> int)
- const ftxwake : (uaddr : uint64# -> int)
+ type ftxtag = uint32
+ impl atomic ftxtag
+
+ const ftxwait : (uaddr : ftxtag#, val : ftxtag, timeout : sys.timespec# -> int)
+ const ftxwake : (uaddr : ftxtag# -> int)
;;
const ftxwait = {uaddr, val, timeout
- -> sys.futex((uaddr : int32#), sys.Futexwait | sys.Futexpriv, val, timeout, Zptr, 0)
+ -> (sys.futex((uaddr : int32#),
+ sys.Futexwait | sys.Futexpriv,
+ (val : int32),
+ timeout,
+ Zptr,
+ 0) : int)
}
const ftxwake = {uaddr
- -> sys.futex((uaddr : int32#), sys.Futexwake | sys.Futexpriv, 1, Zptr, Zptr, 0)
+ -> (sys.futex((uaddr : int32#), sys.Futexwake | sys.Futexpriv, 1, Zptr, Zptr, 0) : int)
}
+
+impl atomic ftxtag =
+ xget = {p; -> (xget32((p : uint32#)) : ftxtag)}
+ xset = {p, v; xset32((p : uint32#), (v : uint32))}
+ xadd = {p, v; -> (xadd32((p : uint32#), (v : uint32)) : ftxtag)}
+ xcas = {p, old, new; -> (xcas32((p : uint32#), (old : uint32), (new : uint32)) : ftxtag)}
+ xchg = {p, v; -> (xchg32((p : uint32#), (v : uint32)) : ftxtag)}
+;;
+
+extern const xget32 : (p : uint32# -> uint32)
+extern const xset32 : (p : uint32#, v : uint32 -> void)
+extern const xadd32 : (p : uint32#, v : uint32 -> uint32)
+extern const xcas32 : (p : uint32#, old: uint32, new : uint32 -> uint32)
+extern const xchg32 : (p : uint32#, v : uint32 -> uint32)
diff --git a/lib/thread/futex+openbsd:6.2.myr b/lib/thread/futex+openbsd:6.2.myr
index bbe2c17..f6dcd05 100644
--- a/lib/thread/futex+openbsd:6.2.myr
+++ b/lib/thread/futex+openbsd:6.2.myr
@@ -3,14 +3,31 @@ use sys
use "common"
pkg thread =
- const ftxwait : (uaddr : uint64#, val : uint64, timeout : sys.timespec# -> int)
- const ftxwake : (uaddr : uint64# -> int)
+ type ftxtag = uint32
+ impl atomic ftxtag
+
+ const ftxwait : (uaddr : ftxtag#, val : ftxtag, timeout : sys.timespec# -> int)
+ const ftxwake : (uaddr : ftxtag# -> int)
;;
const ftxwait = {uaddr, val, timeout
- -> sys.futex((uaddr : uint32#), sys.Futexwait, val, timeout, Zptr)
+ -> sys.futex((uaddr : uint32#), sys.Futexwait, (val : int), timeout, Zptr)
}
const ftxwake = {uaddr
-> sys.futex((uaddr : uint32#), sys.Futexwake, 1, Zptr, Zptr)
}
+
+impl atomic ftxtag =
+ xget = {p; -> (xget32((p : uint32#)) : ftxtag)}
+ xset = {p, v; xset32((p : uint32#), (v : uint32))}
+ xadd = {p, v; -> (xadd32((p : uint32#), (v : uint32)) : ftxtag)}
+ xcas = {p, old, new; -> (xcas32((p : uint32#), (old : uint32), (new : uint32)) : ftxtag)}
+ xchg = {p, v; -> (xchg32((p : uint32#), (v : uint32)) : ftxtag)}
+;;
+
+extern const xget32 : (p : uint32# -> uint32)
+extern const xset32 : (p : uint32#, v : uint32 -> void)
+extern const xadd32 : (p : uint32#, v : uint32 -> uint32)
+extern const xcas32 : (p : uint32#, old: uint32, new : uint32 -> uint32)
+extern const xchg32 : (p : uint32#, v : uint32 -> uint32)
diff --git a/lib/thread/futex+osx.myr b/lib/thread/futex+osx.myr
index c2b47d9..51e3c7a 100644
--- a/lib/thread/futex+osx.myr
+++ b/lib/thread/futex+osx.myr
@@ -1,11 +1,15 @@
use std
use sys
+use "atomic"
use "common"
pkg thread =
- const ftxwait : (uaddr : uint64#, val : uint64, timeout : sys.timespec# -> int)
- const ftxwake : (uaddr : uint64# -> int)
+ type ftxtag = uint64
+ impl atomic ftxtag
+
+ const ftxwait : (uaddr : ftxtag#, val : ftxtag, timeout : sys.timespec# -> int)
+ const ftxwake : (uaddr : ftxtag# -> int)
;;
/*
@@ -14,19 +18,20 @@ pkg thread =
*/
const ftxwait = {uaddr, val, timeout
if timeout == Zptr
- -> sys.ulock_wait(sys.Ulockcompareandwait, uaddr, val, 0)
+ -> sys.ulock_wait(sys.Ulockcompareandwait, (uaddr : uint64#), (val : uint64), 0)
;;
var ts
var err = sys.clock_gettime(`sys.Clockmonotonic, &ts)
std.assert(err == 0, "error: clock_gettime returned {}\n", err)
+ if timeout.sec < ts.sec
+ -> (std.Etimedout : int)
+ ;;
var usec = 0
- if timeout.sec > ts.sec
- var sec = (timeout.sec - ts.sec) * 1000
- std.assert(sec <= 0xffffffff, "error: maximum futex timeout exceeded\n")
- usec = (sec : uint32)
- ;;
+ var sec = (timeout.sec - ts.sec) * 1000
+ std.assert(sec <= 0xffffffff, "error: maximum futex timeout exceeded\n")
+ usec = (sec : uint32)
if timeout.nsec > ts.nsec
var nsec = (timeout.nsec - ts.nsec) / 1000
std.assert(usec + nsec > usec, "error: maximum futex timeout exceeded\n")
@@ -36,9 +41,23 @@ const ftxwait = {uaddr, val, timeout
if usec == 0
-> (std.Etimedout : int)
;;
- -> sys.ulock_wait(sys.Ulockcompareandwait, uaddr, val, 0)
+ -> sys.ulock_wait(sys.Ulockcompareandwait, (uaddr : uint64#), (val : uint64), usec)
}
const ftxwake = {uaddr
- -> sys.ulock_wake(sys.Ulockcompareandwait, uaddr, 0)
+ -> sys.ulock_wake(sys.Ulockcompareandwait, (uaddr : uint64#), 0)
}
+
+impl atomic ftxtag =
+ xget = {p; -> (xget64((p : uint64#)) : ftxtag)}
+ xset = {p, v; xset64((p : uint64#), (v : uint64))}
+ xadd = {p, v; -> (xadd64((p : uint64#), (v : uint64)) : ftxtag)}
+ xcas = {p, old, new; -> (xcas64((p : uint64#), (old : uint64), (new : uint64)) : ftxtag)}
+ xchg = {p, v; -> (xchg64((p : uint64#), (v : uint64)) : ftxtag)}
+;;
+
+extern const xget64 : (p : uint64# -> uint64)
+extern const xset64 : (p : uint64#, v : uint64 -> void)
+extern const xadd64 : (p : uint64#, v : uint64 -> uint64)
+extern const xcas64 : (p : uint64#, old: uint64, new : uint64 -> uint64)
+extern const xchg64 : (p : uint64#, v : uint64 -> uint64)
diff --git a/lib/thread/mutex+futex.myr b/lib/thread/mutex+futex.myr
index 298285d..1a17c60 100644
--- a/lib/thread/mutex+futex.myr
+++ b/lib/thread/mutex+futex.myr
@@ -6,7 +6,7 @@ use "futex"
pkg thread =
type mutex = struct
- _state : uint64
+ _state : ftxtag
;;
const mkmtx : (-> mutex)
diff --git a/lib/thread/sem+futex.myr b/lib/thread/sem+futex.myr
index aa00f4c..76fb285 100644
--- a/lib/thread/sem+futex.myr
+++ b/lib/thread/sem+futex.myr
@@ -7,7 +7,7 @@ use "futex"
pkg thread =
type sem = struct
- _val : uint64
+ _val : ftxtag
;;
const mksem : (v : uint32 -> sem)
@@ -17,7 +17,7 @@ pkg thread =
;;
const mksem = {v
- -> [._val = (v : uint64)]
+ -> [._val = (v : ftxtag)]
}
const semwait = {s