ref: 7b5b914cf702375f8f532c2fe43c04d6eacd1fd6
parent: 7c2f25e309226a9506ea4b37e94e560017e83994
author: iriri <iri@konnichiwastevenspielbergde.su>
date: Sat Jun 23 01:33:08 EDT 2018
Add ftxtag type and add missing casts
--- a/lib/thread/futex+freebsd.myr
+++ b/lib/thread/futex+freebsd.myr
@@ -3,8 +3,11 @@
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 @@
;;
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)
--- a/lib/thread/futex+linux.myr
+++ b/lib/thread/futex+linux.myr
@@ -3,14 +3,36 @@
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)
--- a/lib/thread/futex+openbsd:6.2.myr
+++ b/lib/thread/futex+openbsd:6.2.myr
@@ -3,14 +3,31 @@
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)
--- 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 @@
*/
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 @@
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)
--- a/lib/thread/mutex+futex.myr
+++ b/lib/thread/mutex+futex.myr
@@ -6,7 +6,7 @@
pkg thread =
type mutex = struct
- _state : uint64
+ _state : ftxtag
;;
const mkmtx : (-> mutex)
--- a/lib/thread/sem+futex.myr
+++ b/lib/thread/sem+futex.myr
@@ -7,7 +7,7 @@
pkg thread =
type sem = struct
- _val : uint64
+ _val : ftxtag
;;
const mksem : (v : uint32 -> sem)
@@ -17,7 +17,7 @@
;;
const mksem = {v
- -> [._val = (v : uint64)]
+ -> [._val = (v : ftxtag)]
}
const semwait = {s