summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-11-05 23:30:56 -0800
committerOri Bernstein <ori@eigenstate.org>2018-11-05 23:30:56 -0800
commitb4074b239d8dda2fccc500ee1467ed21987938e9 (patch)
tree67dde27e2d1eded6174e9586252e639bc5c00295
parent3821901ac0c5ef909818d887ffe3d4565ecd469d (diff)
downloadmc-b4074b239d8dda2fccc500ee1467ed21987938e9.tar.gz
TLS implementation for 9front.
-rw-r--r--lib/thread/hookstd.myr1
-rw-r--r--lib/thread/spawn+plan9.myr13
-rw-r--r--lib/thread/tls+plan9.myr73
-rw-r--r--lib/thread/types+plan9.myr6
4 files changed, 93 insertions, 0 deletions
diff --git a/lib/thread/hookstd.myr b/lib/thread/hookstd.myr
index 6f0e9df..ec58146 100644
--- a/lib/thread/hookstd.myr
+++ b/lib/thread/hookstd.myr
@@ -1,4 +1,5 @@
use std
+use sys
use "mutex"
use "tls"
diff --git a/lib/thread/spawn+plan9.myr b/lib/thread/spawn+plan9.myr
index e577e7c..22b63f8 100644
--- a/lib/thread/spawn+plan9.myr
+++ b/lib/thread/spawn+plan9.myr
@@ -1,5 +1,6 @@
use std
use sys
+use "tls"
pkg thread =
type tid = uint64
@@ -8,11 +9,23 @@ pkg thread =
;;
const spawn = {fn
+ var p, s
+
fn = std.fndup(fn)
match sys.rfork(sys.Rfproc | sys.Rfmem)
| 0:
+ if ntlsslots > Staticcap
+ p = getpriv()
+ s = std.slalloc(ntlsslots)
+ p[0] = (s : void#)
+ ;;
fn()
std.fnfree(fn)
+ if ntlsslots > Staticcap
+ p = getpriv()
+ s = (p[0] : void##)[:ntlsslots]
+ std.slfree(s)
+ ;;
std.exit(0)
| -1:
std.fnfree(fn)
diff --git a/lib/thread/tls+plan9.myr b/lib/thread/tls+plan9.myr
new file mode 100644
index 0000000..385658e
--- /dev/null
+++ b/lib/thread/tls+plan9.myr
@@ -0,0 +1,73 @@
+use sys
+use std
+
+use "common"
+use "types"
+
+pkg thread =
+ generic tlsalloc : (-> tlskey(@a#))
+ generic tlsset : (k : tlskey(@a#), v : @a# -> void)
+ generic tlsget : (k : tlskey(@a#) -> @a#)
+ const tid : (-> tid)
+
+ pkglocal const getpriv : (-> void#[:])
+
+ pkglocal var ntlsslots : std.size
+ pkglocal const Staticcap : std.size
+;;
+
+var ntlsslots
+const Staticcap = (sys.Npriv : std.size)
+
+const getpriv = {
+ var p
+
+ p = (sys.tosptr : std.size)
+ p -= sizeof(sys.tos)
+ -> (p : void##)[:sys.Npriv]
+}
+
+
+generic tlsalloc = { -> tlskey(@a#)
+ var s, p
+
+ p = getpriv()
+ if ntlsslots == Staticcap
+ s = std.sldup(p[:sys.Npriv])
+ p[0] = (s : void#)
+ elif ntlsslots > Staticcap
+ s = (p[0] : void##)[:ntlsslots]
+ std.slpush(&s, Zptr)
+ p[0] = (s : void#)
+ ;;
+ ntlsslots++
+ -> (ntlsslots - 1 : tlskey(@a#))
+}
+
+generic tlsset = {k : tlskey(@a#), v : @a#
+ var s, p
+
+ s = getpriv()
+ if ntlsslots < 8
+ s[k] = (v : void#)
+ else
+ p = (s[0] : void##)[:ntlsslots]
+ p[k] = (v : void#)
+ ;;
+}
+
+generic tlsget = {k
+ var s, p
+
+ p = getpriv()
+ if ntlsslots < 8
+ -> (s[k] : @a#)
+ else
+ s = (p[0] : void##)[:ntlsslots]
+ -> (s[k] : @a#)
+ ;;
+}
+
+const tid = {
+ -> (sys.tosptr.pid : tid)
+}
diff --git a/lib/thread/types+plan9.myr b/lib/thread/types+plan9.myr
new file mode 100644
index 0000000..396982a
--- /dev/null
+++ b/lib/thread/types+plan9.myr
@@ -0,0 +1,6 @@
+use sys
+
+pkg thread =
+ type tid = uint32
+ type tlskey(@a) = uint32
+;;