aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/remoteCounter.ml
diff options
context:
space:
mode:
authorGravatar Enrico Tassi <Enrico.Tassi@inria.fr>2014-02-24 11:40:32 +0100
committerGravatar Enrico Tassi <Enrico.Tassi@inria.fr>2014-02-26 14:53:08 +0100
commitd002d775f76ddab45983354022a0f8c59b1af313 (patch)
treec60111f1a613cd9e86bd666ac501fb0986a9a3d5 /lib/remoteCounter.ml
parent2145e0274482017dc8e16c8ee774bc422be930e1 (diff)
remoteCounter: backup/restore
When you resume the compilation of a .vi file, you want to avoid collisions on fresh names.
Diffstat (limited to 'lib/remoteCounter.ml')
-rw-r--r--lib/remoteCounter.ml22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/remoteCounter.ml b/lib/remoteCounter.ml
index e0e2d5cbc..bec46901f 100644
--- a/lib/remoteCounter.ml
+++ b/lib/remoteCounter.ml
@@ -9,8 +9,16 @@
type 'a getter = unit -> 'a
type 'a installer = ('a getter) -> unit
-let new_counter a ~incr ~build =
- let data = ref a in
+type remote_counters_status = (string * Obj.t) list
+
+let counters : remote_counters_status ref = ref []
+
+let (!!) x = !(!x)
+
+let new_counter ~name a ~incr ~build =
+ assert(not (List.mem_assoc name !counters));
+ let data = ref (ref a) in
+ counters := (name, Obj.repr data) :: !counters;
let m = Mutex.create () in
let mk_thsafe_getter f () =
(* - slaves must use a remote counter getter, not this one! *)
@@ -22,7 +30,7 @@ let new_counter a ~incr ~build =
| _ -> ());
Mutex.lock m; let x = f () in Mutex.unlock m;
build x in
- let getter = ref (mk_thsafe_getter (fun () -> data := incr !data; !data)) in
+ let getter = ref(mk_thsafe_getter (fun () -> !data := incr !!data; !!data)) in
let installer f =
(match !Flags.async_proofs_mode with
| Flags.APoff | Flags.APonLazy | Flags.APonParallel 0 ->
@@ -31,3 +39,11 @@ let new_counter a ~incr ~build =
getter := f in
(fun () -> !getter ()), installer
+let backup () = !counters
+
+let restore l =
+ List.iter (fun (name, data) ->
+ assert(List.mem_assoc name !counters);
+ let dataref = Obj.obj (List.assoc name !counters) in
+ !dataref := !!(Obj.obj data))
+ l