shithub: mc

Download patch

ref: 3f8013774a97396ace94769e216614ca4fde42a0
parent: 3484982128cc972ffac988ed8dfa23fc6aaf50f4
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Dec 28 21:16:18 EST 2016

Clean up thread spawning code on linux.

--- a/lib/thread/spawn+linux.myr
+++ b/lib/thread/spawn+linux.myr
@@ -22,22 +22,15 @@
 
 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#))
@@ -45,6 +38,19 @@
 		-> `std.Err "couldn't spawn thread"
 	;;
 	-> `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