aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/remoteCounter.ml
diff options
context:
space:
mode:
authorGravatar gareuselesinge <gareuselesinge@85f007b7-540e-0410-9357-904b9bb8a0f7>2013-08-20 12:43:42 +0000
committerGravatar gareuselesinge <gareuselesinge@85f007b7-540e-0410-9357-904b9bb8a0f7>2013-08-20 12:43:42 +0000
commit16a2717d25096fcbd07b252e775b66b6fbb6d2bd (patch)
treeaa27bd74810dbda95b19097ea486842eb8f7e33a /lib/remoteCounter.ml
parentc5b699f8feb54b7ada2cb6c6754a1909ebedcd3f (diff)
Universe counters on slaves are in sync with master
Simple framework for remote counters. The slaves ask the master for a fresh value. On the master the thread manager answers with a bunch of fresh values (so that further requests can be immediately satisfied). Remote counters are guarded with a mutex on the master, because all slave managers as well as the master thread can access the counter at the same time. I know the name sucks. These counters are remote for the slaves, and local for the master. I'm open to suggestions... git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@16713 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib/remoteCounter.ml')
-rw-r--r--lib/remoteCounter.ml29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/remoteCounter.ml b/lib/remoteCounter.ml
new file mode 100644
index 000000000..1983d2722
--- /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
+