aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.mllib1
-rw-r--r--lib/remoteCounter.ml29
-rw-r--r--lib/remoteCounter.mli14
3 files changed, 44 insertions, 0 deletions
diff --git a/lib/lib.mllib b/lib/lib.mllib
index 5f1314185e..9f29613d19 100644
--- a/lib/lib.mllib
+++ b/lib/lib.mllib
@@ -19,5 +19,6 @@ Dnet
Unionfind
Genarg
Future
+RemoteCounter
Dag
Vcs
diff --git a/lib/remoteCounter.ml b/lib/remoteCounter.ml
new file mode 100644
index 0000000000..1983d27220
--- /dev/null
+++ b/lib/remoteCounter.ml
@@ -0,0 +1,29 @@
+(************************************************************************)
+(* v * The Coq Proof Assistant / The Coq Development Team *)
+(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2012 *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(************************************************************************)
+
+type 'a getter = unit -> 'a
+type 'a installer = ('a getter) -> unit
+
+let new_counter a ~incr ~build =
+ let data = ref a in
+ let m = Mutex.create () in
+ let mk_thsafe_getter f () =
+ (* - slaves must use a remote counter getter, not this one! *)
+ (* - in the main process there is a race condition between slave
+ managers (that are threads) and the main thread, hence the mutex *)
+ if !Flags.coq_slave_mode > 0 then
+ Errors.anomaly(Pp.str"Slave processes must install remote counters");
+ 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 installer f =
+ if !Flags.coq_slave_mode < 1 then
+ Errors.anomaly(Pp.str"Only slave processes can install a remote counter")
+ else getter := f in
+ (fun () -> !getter ()), installer
+
diff --git a/lib/remoteCounter.mli b/lib/remoteCounter.mli
new file mode 100644
index 0000000000..f17f1be3cf
--- /dev/null
+++ b/lib/remoteCounter.mli
@@ -0,0 +1,14 @@
+(************************************************************************)
+(* v * The Coq Proof Assistant / The Coq Development Team *)
+(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2013 *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(************************************************************************)
+
+type 'a getter = unit -> 'a
+type 'a installer = ('a getter) -> unit
+
+val new_counter :
+ 'a -> incr:('a -> 'a) -> build:('a -> 'b) -> 'b getter * 'b installer
+