summaryrefslogtreecommitdiff
path: root/lib/thread
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-05-17 22:00:50 -0700
committerOri Bernstein <ori@eigenstate.org>2016-05-17 22:00:50 -0700
commit7aac15b2bfcc5eec279aa14f9f199685f9d7e0d9 (patch)
treec9434a55ea6850aee7103f608c6333cfe3148d60 /lib/thread
parentc96238b89583ed91e92ad909c507797d00015e95 (diff)
downloadmc-7aac15b2bfcc5eec279aa14f9f199685f9d7e0d9.tar.gz
New syntax for casts.
Diffstat (limited to 'lib/thread')
-rw-r--r--lib/thread/atomic.myr20
-rw-r--r--lib/thread/common.myr2
-rw-r--r--lib/thread/condvar+freebsd.myr12
-rw-r--r--lib/thread/condvar+linux.myr2
-rw-r--r--lib/thread/hookstd.myr10
-rw-r--r--lib/thread/mutex+freebsd.myr6
-rw-r--r--lib/thread/spawn+freebsd.myr22
-rw-r--r--lib/thread/spawn+linux.myr24
-rw-r--r--lib/thread/spawn+openbsd.myr25
-rw-r--r--lib/thread/spawn+osx.myr28
-rw-r--r--lib/thread/spawn+plan9.myr4
11 files changed, 79 insertions, 76 deletions
diff --git a/lib/thread/atomic.myr b/lib/thread/atomic.myr
index a1bb7ae..b9678c7 100644
--- a/lib/thread/atomic.myr
+++ b/lib/thread/atomic.myr
@@ -16,20 +16,20 @@ pkg thread =
;;
impl atomic int32 =
- xget = {p; -> xget32(p castto(uint32#)) castto(int32)}
- xset = {p, v; xset32(p castto(uint32#), v castto(uint32))}
- xadd = {p, v; -> xadd32(p castto(uint32#), v castto(uint32)) castto(int32)}
- xcas = {p, old, new; -> xcas32(p castto(uint32#), old castto(uint32), new castto(uint32)) castto(int32)}
- xchg = {p, v; -> xchg32(p castto(uint32#), v castto(uint32)) castto(int32)}
+ xget = {p; -> (xget32((p : uint32#)) : int32)}
+ xset = {p, v; xset32((p : uint32#), (v : uint32))}
+ xadd = {p, v; -> (xadd32((p : uint32#), (v : uint32)) : int32)}
+ xcas = {p, old, new; -> (xcas32((p : uint32#), (old : uint32), (new : uint32)) : int32)}
+ xchg = {p, v; -> (xchg32((p : uint32#), (v : uint32)) : int32)}
;;
impl atomic int64 =
- xget = {p; -> xget64(p castto(uint64#)) castto(int64)}
- xset = {p, v; xset64(p castto(uint64#), v castto(uint64))}
- xadd = {p, v; -> xadd64(p castto(uint64#), v castto(uint64)) castto(int64)}
- xcas = {p, old, new; -> xcas64(p castto(uint64#), old castto(uint64), new castto(uint64)) castto(int64)}
- xchg = {p, v; -> xchg64(p castto(uint64#), v castto(uint64)) castto(int64)}
+ xget = {p; -> (xget64((p : uint64#)) : int64)}
+ xset = {p, v; xset64((p : uint64#), (v : uint64))}
+ xadd = {p, v; -> (xadd64((p : uint64#), (v : uint64)) : int64)}
+ xcas = {p, old, new; -> (xcas64((p : uint64#), (old : uint64), (new : uint64)) : int64)}
+ xchg = {p, v; -> (xchg64((p : uint64#), (v : uint64)) : int64)}
;;
impl atomic uint32 =
diff --git a/lib/thread/common.myr b/lib/thread/common.myr
index b88a480..0268af3 100644
--- a/lib/thread/common.myr
+++ b/lib/thread/common.myr
@@ -1,5 +1,5 @@
use std
pkg thread =
- generic Zptr = 0 castto(@a#)
+ generic Zptr = (0 : @a#)
;;
diff --git a/lib/thread/condvar+freebsd.myr b/lib/thread/condvar+freebsd.myr
index eb04866..24e5a32 100644
--- a/lib/thread/condvar+freebsd.myr
+++ b/lib/thread/condvar+freebsd.myr
@@ -29,9 +29,9 @@ const condwait = {cond
seq = cond._seq
mtxunlock(mtx)
- sys.umtx_op(&cond._seq castto(void#), \
+ sys.umtx_op((&cond._seq : void#), \
sys.Umtxwaituintpriv, \
- seq castto(uint64), \
+ (seq : uint64), \
Zptr, Zptr)
/*
@@ -40,20 +40,20 @@ const condwait = {cond
unlocker of the mutex.
*/
while xchg(&mtx._state, Contended) != Unlocked
- sys.umtx_op(&mtx._state castto(void#), \
+ sys.umtx_op((&mtx._state : void#), \
sys.Umtxwaituintpriv, \
- Contended castto(uint64), \
+ (Contended : uint64), \
Zptr, Zptr)
;;
}
const condsignal = {cond : cond#
xadd(&cond._seq, 1)
- sys.umtx_op(&cond._seq castto(void#), sys.Umtxwakepriv, 1, Zptr, Zptr)
+ sys.umtx_op((&cond._seq : void#), sys.Umtxwakepriv, 1, Zptr, Zptr)
}
const condbroadcast = {cond : cond#
xadd(&cond._seq, 1)
- sys.umtx_op(&cond._seq castto(void#), sys.Umtxwakepriv, 0x7ffffff, Zptr, Zptr)
+ sys.umtx_op((&cond._seq : void#), sys.Umtxwakepriv, 0x7ffffff, Zptr, Zptr)
}
diff --git a/lib/thread/condvar+linux.myr b/lib/thread/condvar+linux.myr
index 2d9aba3..9e288d7 100644
--- a/lib/thread/condvar+linux.myr
+++ b/lib/thread/condvar+linux.myr
@@ -55,7 +55,7 @@ const condbroadcast = {cond : cond#
requeueing
*/
sys.futex(&cond._seq, sys.Futexcmprequeue | sys.Futexpriv, \
- 1, 0x7fffffff castto(sys.timespec#), \
+ 1, (0x7fffffff : sys.timespec#), \
&cond._mtx._state, cond._seq)
}
diff --git a/lib/thread/hookstd.myr b/lib/thread/hookstd.myr
index de83178..ea56193 100644
--- a/lib/thread/hookstd.myr
+++ b/lib/thread/hookstd.myr
@@ -13,11 +13,11 @@ const __init__ = {
netlck = mkmtx()
envlck = mkmtx()
std.__lockinit( \
- &memlck castto(void#), \
- &netlck castto(void#), \
- &envlck castto(void#), \
- {mtx; mtxlock(mtx castto(mutex#))}, \
- {mtx; mtxunlock(mtx castto(mutex#))} \
+ (&memlck : void#), \
+ (&netlck : void#), \
+ (&envlck : void#), \
+ {mtx; mtxlock((mtx : mutex#))}, \
+ {mtx; mtxunlock((mtx : mutex#))} \
)
}
diff --git a/lib/thread/mutex+freebsd.myr b/lib/thread/mutex+freebsd.myr
index 7ae2b15..d66fd53 100644
--- a/lib/thread/mutex+freebsd.myr
+++ b/lib/thread/mutex+freebsd.myr
@@ -51,9 +51,9 @@ const mtxlock = {mtx
while c != Unlocked
sys.umtx_op( \
- &mtx._state castto(void#), \
+ (&mtx._state : void#), \
sys.Umtxwaituintpriv, \
- Contended castto(uint64), \
+ (Contended : uint64), \
Zptr, Zptr)
c = xchg(&mtx._state, Contended)
;;
@@ -76,6 +76,6 @@ const mtxunlock = {mtx
;;
/* wake all threads: for some reason nwake */
- sys.umtx_op(&mtx._state castto(void#), sys.Umtxwakepriv, 1, Zptr, Zptr)
+ sys.umtx_op((&mtx._state : void#), sys.Umtxwakepriv, 1, Zptr, Zptr)
}
diff --git a/lib/thread/spawn+freebsd.myr b/lib/thread/spawn+freebsd.myr
index 63d97fe..9bf75e4 100644
--- a/lib/thread/spawn+freebsd.myr
+++ b/lib/thread/spawn+freebsd.myr
@@ -25,46 +25,46 @@ const spawnstk = {fn, sz
;;
tid = -1
/* find top of stack */
- tos = (stk castto(std.intptr)) + (sz castto(std.intptr))
+ tos = (stk : std.intptr) + (sz : std.intptr)
/* store the stack size */
tos -= sizeof(sys.size)
sz -= sizeof(sys.size)
- szp = tos castto(sys.size#)
+ szp = (tos : sys.size#)
szp# = Stacksz
/* store the function we call */
tos -= sizeof((->void))
sz -= sizeof((->void))
- fp = tos castto((->void)#)
+ fp = (tos : (->void)#)
fp# = fn
ret = sys.thr_new(&[
- .startfn = startthread castto(void#),
- .arg = tos castto(void#),
- .stkbase = stk castto(byte#),
+ .startfn = (startthread : void#),
+ .arg = (tos : void#),
+ .stkbase = (stk : byte#),
.stksz = sz,
.tid = &ctid,
.ptid = &tid,
.flags = 2,
- .rtp = 0 castto(sys.rtprio#)
+ .rtp = (0 : sys.rtprio#)
], sizeof(sys.thrparam))
if ret < 0
-> `std.Fail "couldn't spawn thread"
;;
- -> `std.Ok tid castto(tid)
+ -> `std.Ok (tid : tid)
}
const getstk = {sz
var p, m
- p = sys.mmap(0 castto(byte#), sz, sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)
+ p = sys.mmap((0 : byte#), sz, sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)
if p == sys.Mapbad
-> p
;;
- m = p castto(std.intptr)
- -> m castto(byte#)
+ m = (p : std.intptr)
+ -> (m : byte#)
}
const startthread = {fn : (-> void)#
diff --git a/lib/thread/spawn+linux.myr b/lib/thread/spawn+linux.myr
index a144374..20e1de8 100644
--- a/lib/thread/spawn+linux.myr
+++ b/lib/thread/spawn+linux.myr
@@ -28,36 +28,36 @@ const spawnstk = {fn, sz
if stk == sys.Mapbad
-> `std.Fail "couldn't get stack"
;;
- tos = stk castto(std.intptr)
+ tos = (stk : std.intptr)
tos -= sizeof(int64)
- szp = tos castto(sys.size#)
+ szp = (tos : sys.size#)
szp# = Stacksz
tos -= sizeof((->void))
- fp = tos castto((->void)#)
+ fp = (tos : (->void)#)
fp# = fn
ret = sys.fnclone(Thrflag, \
- tos castto(byte#),\
- &tid, 0 castto(byte#), \
- &ctid, 0 castto(byte#), \
- startthread castto(void#)) castto(tid)
+ (tos : byte#),\
+ &tid, (0 : byte#), \
+ &ctid, (0 : byte#), \
+ (startthread : void#))
if ret < 0
-> `std.Fail "couldn't spawn thread"
;;
- -> `std.Ok ret
+ -> `std.Ok (ret : tid)
}
const getstk = {sz
var p, m
- p = sys.mmap(0 castto(byte#), sz, sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)
+ p = sys.mmap((0 : byte#), sz, sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)
if p == sys.Mapbad
-> p
;;
/* stack starts at the top of memory and grows down. */
- m = p castto(std.intptr)
- m += sz castto(std.intptr)
- -> m castto(byte#)
+ m = (p : std.intptr)
+ m += (sz : std.intptr)
+ -> (m : byte#)
}
const startthread = {fn : (-> void)
diff --git a/lib/thread/spawn+openbsd.myr b/lib/thread/spawn+openbsd.myr
index d330b56..f0e1fd4 100644
--- a/lib/thread/spawn+openbsd.myr
+++ b/lib/thread/spawn+openbsd.myr
@@ -23,38 +23,41 @@ const spawnstk = {fn, sz
-> `std.Fail "couldn't get stack"
;;
/* store size */
- tos = stk castto(std.intptr)
+ tos = (stk : std.intptr)
tos -= sizeof(int64)
- szp = tos castto(sys.size#)
+ szp = (tos : sys.size#)
szp# = Stacksz
/* store func */
tos -= sizeof((->void))
- fp = tos castto((->void)#)
+ fp = (tos : (->void)#)
fp# = fn
tfp = [
- .tcb = 0 castto(void#),
+ .tcb = (0 : void#),
.tid = &ret,
- .stk = tos castto(byte#),
+ .stk = (tos : byte#),
]
- if sys.__tfork_thread(&tfp, sizeof(sys.tforkparams), startthread castto(void#), 0 castto(void#)) < 0
+ if sys.__tfork_thread(&tfp, \
+ sizeof(sys.tforkparams), \
+ (startthread : void#), \
+ (0 : void#)) < 0
-> `std.Fail "couldn't spawn thread"
;;
- -> `std.Ok (ret castto(tid))
+ -> `std.Ok (ret : tid)
}
const getstk = {sz
var p, m
- p = sys.mmap(0 castto(byte#), sz, sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)
+ p = sys.mmap((0 : byte#), sz, sys.Mprotrw, sys.Mpriv | sys.Manon, -1, 0)
if p == sys.Mapbad
-> p
;;
/* stack starts at the top of memory and grows down. */
- m = p castto(std.intptr)
- m += sz castto(std.intptr)
- -> m castto(byte#)
+ m = (p : std.intptr)
+ m += (sz : std.intptr)
+ -> (m : byte#)
}
const startthread = {fn : (-> void)
diff --git a/lib/thread/spawn+osx.myr b/lib/thread/spawn+osx.myr
index b9d5457..0ae8e1b 100644
--- a/lib/thread/spawn+osx.myr
+++ b/lib/thread/spawn+osx.myr
@@ -16,12 +16,12 @@ const __init__ = {
var ret
ret = sys.bsdthread_register(\
- start castto(void#), \ /* start */
- 0 castto(void#), \ /* wqthread */
- 0 castto(uint32), \ /* sz */
- 0 castto(uint32), \ /* dummy */
- 0 castto(void#), \ /* targconc */
- 0 castto(uint32)) /* queueoff */
+ (start : void#), \ /* start */
+ (0 : void#), \ /* wqthread */
+ (0 : uint32), \ /* sz */
+ (0 : uint32), \ /* dummy */
+ (0 : void#), \ /* targconc */
+ (0 : uint32)) /* queueoff */
if ret < 0
std.fatal("unable to init threads: {}", ret)
;;
@@ -37,24 +37,24 @@ const spawnstk = {fn, sz
var tid : tid, ret
- std.put("...hi? fn={}\n", fn castto(void#))
+ std.put("...hi? fn={}\n", (fn : void#))
ret = sys.bsdthread_create( \
- fn castto(void#), \
+ (fn : void#), \
envptr(&fn), \
- sz castto(void#), \
- 0 castto(void#), \
+ (sz : void#), \
+ (0 : void#), \
0)
- if ret == (-1 castto(void#))
+ if ret == (-1 : void#)
-> `std.Fail "couldn't spawn thread"
;;
- -> `std.Ok ret castto(tid)
+ -> `std.Ok (ret : tid)
}
const envptr = {fn
var repr : std.intptr[2]
- repr = (fn castto(std.intptr[2]#))#
- -> repr[0] castto(void#)
+ repr = (fn : std.intptr[2]#)#
+ -> (repr[0] : void#)
}
diff --git a/lib/thread/spawn+plan9.myr b/lib/thread/spawn+plan9.myr
index 4397851..2c6e856 100644
--- a/lib/thread/spawn+plan9.myr
+++ b/lib/thread/spawn+plan9.myr
@@ -13,6 +13,6 @@ const spawn = {fn
fn()
std.exit(0)
| -1: -> `std.Fail "unable to spawn thread"
- | thr: -> `std.Ok thr castto(tid)
+ | thr: -> `std.Ok (thr : tid)
;;
-} \ No newline at end of file
+}