Browse Source

[eval] make thread handling thread-safe

Simon Krajewski 6 years ago
parent
commit
1fc84df261
3 changed files with 4 additions and 8 deletions
  1. 2 2
      src/macro/eval/evalContext.ml
  2. 1 2
      src/macro/eval/evalMain.ml
  3. 1 4
      src/macro/eval/evalStdLib.ml

+ 2 - 2
src/macro/eval/evalContext.ml

@@ -244,7 +244,7 @@ and context = {
 	(* eval *)
 	(* eval *)
 	toplevel : value;
 	toplevel : value;
 	eval : eval;
 	eval : eval;
-	evals : eval DynArray.t;
+	mutable evals : eval IntMap.t;
 	mutable exception_stack : (pos * env_kind) list;
 	mutable exception_stack : (pos * env_kind) list;
 }
 }
 
 
@@ -256,7 +256,7 @@ let select ctx = get_ctx_ref := (fun() -> ctx)
 
 
 let get_eval ctx =
 let get_eval ctx =
     let id = Thread.id (Thread.self()) in
     let id = Thread.id (Thread.self()) in
-    if id = 0 then ctx.eval else DynArray.unsafe_get ctx.evals id
+    if id = 0 then ctx.eval else IntMap.find id ctx.evals
 
 
 let rec kind_name eval kind =
 let rec kind_name eval kind =
 	let rec loop kind env = match kind with
 	let rec loop kind env = match kind with

+ 1 - 2
src/macro/eval/evalMain.ml

@@ -102,11 +102,10 @@ let create com api is_macro =
 			debug
 			debug
 	in
 	in
 	let detail_times = Common.defined com Define.EvalTimes in
 	let detail_times = Common.defined com Define.EvalTimes in
-	let evals = DynArray.create () in
 	let eval = {
 	let eval = {
 		env = null_env;
 		env = null_env;
 	} in
 	} in
-	DynArray.add evals eval;
+	let evals = IntMap.singleton 0 eval in
 	let rec ctx = {
 	let rec ctx = {
 		ctx_id = !sid;
 		ctx_id = !sid;
 		is_macro = is_macro;
 		is_macro = is_macro;

+ 1 - 4
src/macro/eval/evalStdLib.ml

@@ -3001,10 +3001,7 @@ let init_constructors builtins =
 				let f () =
 				let f () =
 					let id = Thread.id (Thread.self()) in
 					let id = Thread.id (Thread.self()) in
 					let new_eval = {env = null_env} in
 					let new_eval = {env = null_env} in
-					if DynArray.length ctx.evals = id then
-						DynArray.add ctx.evals new_eval
-					else
-						DynArray.set ctx.evals id new_eval;
+					ctx.evals <- IntMap.add id new_eval ctx.evals;
 					try
 					try
 						ignore(call_value f []);
 						ignore(call_value f []);
 					with RunTimeException(v,stack,p) ->
 					with RunTimeException(v,stack,p) ->