summaryrefslogtreecommitdiff
path: root/lib/thread
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-12-29 02:16:18 -0500
committerOri Bernstein <ori@eigenstate.org>2016-12-29 02:16:18 -0500
commit3f8013774a97396ace94769e216614ca4fde42a0 (patch)
tree274d6c749606db4efca71827a9be3c726977bdcb /lib/thread
parent3484982128cc972ffac988ed8dfa23fc6aaf50f4 (diff)
downloadmc-3f8013774a97396ace94769e216614ca4fde42a0.tar.gz
Clean up thread spawning code on linux.
Diffstat (limited to 'lib/thread')
-rw-r--r--lib/thread/spawn+linux.myr24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/thread/spawn+linux.myr b/lib/thread/spawn+linux.myr
index 524144c..54bac25 100644
--- a/lib/thread/spawn+linux.myr
+++ b/lib/thread/spawn+linux.myr
@@ -22,22 +22,15 @@ const spawn = {fn
const spawnstk = {fn, sz
var stk : byte#, tid, ctid, ret
- var szp, fp, tos
stk = getstk(sz)
if stk == sys.Mapbad
-> `std.Err "couldn't get stack"
;;
- tos = (stk : std.intptr)
- tos -= sizeof(int64)
- szp = (tos : sys.size#)
- szp# = Stacksz
- tos -= sizeof((->void))
- fp = (tos : (->void)#)
- fp# = fn
+ stk = initstack(stk, fn, Stacksz)
ret = sys.fnclone(Thrflag, \
- (tos : byte#),\
+ (stk : byte#),\
&tid, (0 : byte#), \
&ctid, (0 : byte#), \
(startthread : void#))
@@ -47,6 +40,19 @@ const spawnstk = {fn, sz
-> `std.Ok (ret : tid)
}
+const initstack = {stk, fn, sz
+ var tos, szp, fp
+
+ tos = (stk : std.intptr)
+ tos -= sizeof(int64)
+ szp = (tos : sys.size#)
+ szp# = sz
+ tos -= sizeof((->void))
+ fp = (tos : (->void)#)
+ fp# = fn
+ -> (tos : byte#)
+}
+
const getstk = {sz
var p, m