summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-06-22 21:10:13 -0700
committerOri Bernstein <ori@eigenstate.org>2018-06-22 21:10:13 -0700
commite3843e8fa26afff64728ffe93ef77f0b10a1f109 (patch)
tree5d04efa767190d1897f97b4f00781258c002437b
parent7b5b914cf702375f8f532c2fe43c04d6eacd1fd6 (diff)
downloadmc-e3843e8fa26afff64728ffe93ef77f0b10a1f109.tar.gz
Fix compilation and clean up code.
Use "atomic" was needed in the non-OSX platforms, to fix the build. The repated 'extern' declarations were also deleted, turning the declarations in atomic.myr into extern declarations. Semaphores were also cleaned up on Plan 9.
-rw-r--r--lib/sys/sys+plan9-x64.myr6
-rw-r--r--lib/thread/atomic.myr39
-rw-r--r--lib/thread/futex+freebsd.myr9
-rw-r--r--lib/thread/futex+linux.myr7
-rw-r--r--lib/thread/futex+openbsd:6.2.myr6
-rw-r--r--lib/thread/futex+osx.myr6
-rw-r--r--lib/thread/mutex+plan9.myr4
-rw-r--r--lib/thread/sem+plan9.myr13
8 files changed, 36 insertions, 54 deletions
diff --git a/lib/sys/sys+plan9-x64.myr b/lib/sys/sys+plan9-x64.myr
index 33541fe..9681bfe 100644
--- a/lib/sys/sys+plan9-x64.myr
+++ b/lib/sys/sys+plan9-x64.myr
@@ -159,9 +159,9 @@ pkg sys =
const exec : (bin : byte[:], args : byte[:][:] -> int64)
const brk_ : (endp : byte# -> int64)
const nsec : (-> uint64)
- const semacquire : (addr : uint32#, block : int -> int)
- const tsemacquire : (addr : uint32#, ms : uint32 -> int)
- const semrelease : (addr : uint32#, count : int32 -> int32)
+ const semacquire : (addr : int32#, block : int -> int)
+ const tsemacquire : (addr : int32#, ms : int32 -> int)
+ const semrelease : (addr : int32#, count : int32 -> int32)
const rendezvous : (tag : void#, val : void# -> void#)
diff --git a/lib/thread/atomic.myr b/lib/thread/atomic.myr
index c2b7e8a..f71528f 100644
--- a/lib/thread/atomic.myr
+++ b/lib/thread/atomic.myr
@@ -19,6 +19,26 @@ pkg thread =
generic xsetptr : (p : @a##, v : std.option(@a#) -> void)
generic xcasptr : (p : @a##, old : std.option(@a#), new : std.option(@a#) -> std.option(@a#))
generic xchgptr : (p : @a##, new : std.option(@a#) -> std.option(@a#))
+
+ pkglocal extern const xget32 : (p : uint32# -> uint32)
+ pkglocal extern const xget64 : (p : uint64# -> uint64)
+ pkglocal extern const xgetp : (p : std.intptr# -> std.intptr)
+
+ pkglocal extern const xset32 : (p : uint32#, v : uint32 -> void)
+ pkglocal extern const xset64 : (p : uint64#, v : uint64 -> void)
+ pkglocal extern const xsetp : (p : std.intptr#, v : std.intptr -> void)
+
+ pkglocal extern const xadd32 : (p : uint32#, v : uint32 -> uint32)
+ pkglocal extern const xadd64 : (p : uint64#, v : uint64 -> uint64)
+ pkglocal extern const xaddp : (p : std.intptr#, v : std.intptr -> std.intptr)
+
+ pkglocal extern const xcas32 : (p : uint32#, old: uint32, new : uint32 -> uint32)
+ pkglocal extern const xcas64 : (p : uint64#, old: uint64, new : uint64 -> uint64)
+ pkglocal extern const xcasp : (p : std.intptr#, old: std.intptr, new : std.intptr -> std.intptr)
+
+ pkglocal extern const xchg32 : (p : uint32#, v : uint32 -> uint32)
+ pkglocal extern const xchg64 : (p : uint64#, v : uint64 -> uint64)
+ pkglocal extern const xchgp : (p : std.intptr#, v : std.intptr -> std.intptr)
;;
impl atomic int32 =
@@ -88,22 +108,3 @@ generic xchgptr = {p, new
;;
}
-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 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/futex+freebsd.myr b/lib/thread/futex+freebsd.myr
index 3eb9ccb..f659b3a 100644
--- a/lib/thread/futex+freebsd.myr
+++ b/lib/thread/futex+freebsd.myr
@@ -1,5 +1,6 @@
use sys
+use "atomic"
use "common"
pkg thread =
@@ -23,7 +24,7 @@ const ftxwait = {uaddr, val, timeout
-> sys.umtx_op((uaddr : void#),
sys.Umtxwaituintpriv,
(val : uint64),
- (sys.sizeof(sys._umtx_time) : void#),
+ (sizeof(sys._umtx_time) : void#),
(&ut : void#))
}
@@ -38,9 +39,3 @@ impl atomic 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 39aabc3..32a652d 100644
--- a/lib/thread/futex+linux.myr
+++ b/lib/thread/futex+linux.myr
@@ -1,5 +1,6 @@
use sys
+use "atomic"
use "common"
pkg thread =
@@ -30,9 +31,3 @@ impl atomic 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 f6dcd05..8283fe1 100644
--- a/lib/thread/futex+openbsd:6.2.myr
+++ b/lib/thread/futex+openbsd:6.2.myr
@@ -1,5 +1,6 @@
use sys
+use "atomic"
use "common"
pkg thread =
@@ -26,8 +27,3 @@ impl atomic 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 51e3c7a..7c74f56 100644
--- a/lib/thread/futex+osx.myr
+++ b/lib/thread/futex+osx.myr
@@ -55,9 +55,3 @@ impl atomic 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+plan9.myr b/lib/thread/mutex+plan9.myr
index e91cd90..e2e1207 100644
--- a/lib/thread/mutex+plan9.myr
+++ b/lib/thread/mutex+plan9.myr
@@ -7,8 +7,8 @@ use "common"
pkg thread =
type mutex = struct
- _state : uint32
- _sem : uint32
+ _state : int32
+ _sem : int32
;;
const mkmtx : (-> mutex)
diff --git a/lib/thread/sem+plan9.myr b/lib/thread/sem+plan9.myr
index 84ecce7..7508e57 100644
--- a/lib/thread/sem+plan9.myr
+++ b/lib/thread/sem+plan9.myr
@@ -6,8 +6,8 @@ use "common"
pkg thread =
type sem = struct
- _user : int32
- _kern : int32
+ _user : uint32
+ _kern : uint32
;;
const mksem : (v : uint32 -> sem)
@@ -17,16 +17,17 @@ pkg thread =
;;
const mksem = {v
- -> [._user = v, ._kern = 0]
+ std.assert((v : int32) > 0, "semaphore overflowed")
+ -> [._user = (v : int32), ._kern = 0]
}
const semwait = {s
var u = xadd(&s._user, -1)
- std.assert(u != 0xffffffff, "error: semaphore underflowed\n")
+ std.assert(u != ~0, "error: semaphore underflowed\n")
/* When the userspace value is negative we fall back on the kernel semaphore */
if u <= 0
- while sys.semacquire((&s._kern : uint32), 1) < 0
+ while sys.semacquire(&s._kern , 1) < 0
/* Interrupted, retry */
;;
;;
@@ -49,6 +50,6 @@ const sempost = {s
var u = xadd(&s._user, 1)
std.assert(u != 0x7fffffff, "error: semaphore overflowed\n")
if u < 0
- sys.semrelease((&s._kern : uint32), 1)
+ sys.semrelease(&s._kern, 1)
;;
}