summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-11-03 16:43:48 -0700
committerOri Bernstein <ori@eigenstate.org>2018-11-03 16:43:48 -0700
commit205416ed364a55ee1792123c2fd73c949600aa50 (patch)
treee0b879eb7a38cb9bd3637d4ede5121c65fbc634d
parent183f3d40a1dbc2254f1e01de21eb022996f40ad2 (diff)
downloadmc-205416ed364a55ee1792123c2fd73c949600aa50.tar.gz
Add tls hooks to libstd.
-rw-r--r--lib/std/threadhooks.myr17
-rw-r--r--lib/thread/hookstd.myr7
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/std/threadhooks.myr b/lib/std/threadhooks.myr
index 71f4d4c..9b04cf3 100644
--- a/lib/std/threadhooks.myr
+++ b/lib/std/threadhooks.myr
@@ -1,6 +1,9 @@
use "die"
pkg std =
+ type thrdata = struct
+ ;;
+
pkglocal var lock : (l : void# -> void)
pkglocal var unlock : (l : void# -> void)
pkglocal var memlck : void#
@@ -12,18 +15,24 @@ pkg std =
net : void#, \
env : void#, \
lck : (l : void# -> void), \
- unlck : (l : void# -> void) \
+ unlck : (l : void# -> void), \
+ tlsget : (-> thrdata#), \
+ tlsset : (v : thrdata# -> void) \
-> void)
;;
/* thread lock wrapper functions */
var lock
var unlock
+var tlsget
+var tlsset
/* locks for various parts of libstd */
var memlck
var netlck
var envlck
+var thrptr
+
/*
work around compiler bug: we don't generate
syms for the funcs with an initializer
@@ -31,13 +40,17 @@ syms for the funcs with an initializer
const __init__ = {
lock = {l; }
unlock = {l; }
+ tlsget = {; -> thrptr}
+ tlsset = {v; thrptr = v}
}
-const __lockinit = {mem, net, env, lck, unlck
+const __lockinit = {mem, net, env, lck, unlck, tlsget_, tlset_
memlck = mem
netlck = net
envlck = env
lock = lck
unlock = unlck
+ tlsget = tlsget_
+ tlsget = tlsget_
}
diff --git a/lib/thread/hookstd.myr b/lib/thread/hookstd.myr
index ea56193..6f0e9df 100644
--- a/lib/thread/hookstd.myr
+++ b/lib/thread/hookstd.myr
@@ -1,5 +1,6 @@
use std
use "mutex"
+use "tls"
pkg thread =
;;
@@ -7,17 +8,21 @@ pkg thread =
var memlck
var netlck
var envlck
+var stdtls
const __init__ = {
memlck = mkmtx()
netlck = mkmtx()
envlck = mkmtx()
+ stdtls = tlsalloc()
std.__lockinit( \
(&memlck : void#), \
(&netlck : void#), \
(&envlck : void#), \
{mtx; mtxlock((mtx : mutex#))}, \
- {mtx; mtxunlock((mtx : mutex#))} \
+ {mtx; mtxunlock((mtx : mutex#))}, \
+ {; -> tlsget(stdtls)}, \
+ {val; tlsset(stdtls, val)} \
)
}