added thread data (formerly global ref in ML/ml_context.ML);
authorwenzelm
Wed, 26 Mar 2008 22:40:03 +0100
changeset 26413 003dd6155870
parent 26412 0918f5c0bbca
child 26414 2780de5a1422
added thread data (formerly global ref in ML/ml_context.ML); renamed ML_Context.>> to Context.>> (again);
src/Pure/context.ML
--- a/src/Pure/context.ML	Wed Mar 26 22:40:02 2008 +0100
+++ b/src/Pure/context.ML	Wed Mar 26 22:40:03 2008 +0100
@@ -63,6 +63,12 @@
   val proof_map: (generic -> generic) -> proof -> proof
   val theory_of: generic -> theory   (*total*)
   val proof_of: generic -> proof     (*total*)
+  (*thread data*)
+  val thread_data: unit -> generic option
+  val the_thread_data: unit -> generic
+  val set_thread_data: generic option -> unit
+  val setmp_thread_data: generic option -> ('a -> 'b) -> 'a -> 'b
+  val >> : (theory -> theory) -> unit
   (*delayed setup*)
   val add_setup: (theory -> theory) -> unit
   val setup: unit -> theory -> theory
@@ -503,6 +509,29 @@
 
 
 
+(** thread data **)
+
+local val tag = Universal.tag () : generic option Universal.tag in
+
+fun thread_data () =
+  (case Multithreading.get_data tag of
+    SOME (SOME context) => SOME context
+  | _ => NONE);
+
+fun the_thread_data () =
+  (case thread_data () of
+    SOME context => context
+  | _ => error "Unknown context");
+
+fun set_thread_data context = Multithreading.put_data (tag, context);
+fun setmp_thread_data context = Library.setmp_thread_data tag (thread_data ()) context;
+
+fun >> f = set_thread_data (SOME (map_theory f (the_thread_data ())));
+
+end;
+
+
+
 (** delayed theory setup **)
 
 local