src/Pure/PIDE/execution.ML
changeset 56292 1a91a0da65ab
parent 56291 e79f76a48449
child 56296 5413b6379c0e
     1.1 --- a/src/Pure/PIDE/execution.ML	Wed Mar 26 12:15:42 2014 +0100
     1.2 +++ b/src/Pure/PIDE/execution.ML	Wed Mar 26 12:32:51 2014 +0100
     1.3 @@ -15,9 +15,10 @@
     1.4    val peek: Document_ID.exec -> Future.group list
     1.5    val cancel: Document_ID.exec -> unit
     1.6    val terminate: Document_ID.exec -> unit
     1.7 -  val fork: {name: string, pos: Position.T, pri: int} -> (unit -> 'a) -> 'a future
     1.8 -  val print: (serial -> unit) -> unit
     1.9 -  val apply_prints: Document_ID.exec -> unit
    1.10 +  type params = {name: string, pos: Position.T, pri: int}
    1.11 +  val fork: params -> (unit -> 'a) -> 'a future
    1.12 +  val print: params -> (serial -> unit) -> unit
    1.13 +  val fork_prints: Document_ID.exec -> unit
    1.14    val purge: Document_ID.exec list -> unit
    1.15    val reset: unit -> Future.group list
    1.16    val shutdown: unit -> unit
    1.17 @@ -28,7 +29,8 @@
    1.18  
    1.19  (* global state *)
    1.20  
    1.21 -type exec_state = Future.group list * (unit -> unit) list;  (*active forks, prints*)
    1.22 +type print = {name: string, pri: int, body: unit -> unit};
    1.23 +type exec_state = Future.group list * print list;  (*active forks, prints*)
    1.24  type state =
    1.25    Document_ID.execution * (*overall document execution*)
    1.26    exec_state Inttab.table;  (*running command execs*)
    1.27 @@ -88,7 +90,9 @@
    1.28    let val props = Markup.properties [(Markup.taskN, Task_Queue.str_of_task task)]
    1.29    in Output.status (implode (map (Markup.markup_only o props) markups)) end;
    1.30  
    1.31 -fun fork {name, pos, pri} e =
    1.32 +type params = {name: string, pos: Position.T, pri: int};
    1.33 +
    1.34 +fun fork ({name, pos, pri}: params) e =
    1.35    uninterruptible (fn _ => Position.setmp_thread_data pos (fn () =>
    1.36      let
    1.37        val exec_id = the_default 0 (Position.parse_id pos);
    1.38 @@ -128,23 +132,23 @@
    1.39  
    1.40  (* print *)
    1.41  
    1.42 -fun print pr =
    1.43 +fun print ({name, pos, pri}: params) pr =
    1.44    change_state (apsnd (fn execs =>
    1.45      let
    1.46 -      val exec_id = the_default 0 (Position.parse_id (Position.thread_data ()));
    1.47 +      val exec_id = the_default 0 (Position.parse_id pos);
    1.48        val i = serial ();
    1.49 +      val print = {name = name, pri = pri, body = fn () => pr i};
    1.50      in
    1.51        (case Inttab.lookup execs exec_id of
    1.52 -        SOME (groups, prints) =>
    1.53 -          Inttab.update (exec_id, (groups, (fn () => pr i) :: prints)) execs
    1.54 +        SOME (groups, prints) => Inttab.update (exec_id, (groups, print :: prints)) execs
    1.55        | NONE => raise Fail (unregistered exec_id))
    1.56      end));
    1.57  
    1.58 -fun apply_prints exec_id =
    1.59 +fun fork_prints exec_id =
    1.60    (case Inttab.lookup (#2 (get_state ())) exec_id of
    1.61      SOME (_, prints) =>
    1.62        if null prints orelse null (tl prints) orelse not (Multithreading.enabled ())
    1.63 -      then List.app (fn e => e ()) (rev prints)
    1.64 +      then List.app (fn {body, ...} => body ()) (rev prints)
    1.65        else
    1.66          let
    1.67            val pos = Position.thread_data ();
    1.68 @@ -152,8 +156,10 @@
    1.69              (case Future.worker_task () of
    1.70                SOME task => Task_Queue.pri_of_task task
    1.71              | NONE => 0);
    1.72 -          val futures = map (fork {name = "Execution.print", pos = pos, pri = pri}) (rev prints);
    1.73 -        in ignore (Future.joins futures) end
    1.74 +        in
    1.75 +          List.app (fn {name, pri, body} =>
    1.76 +            ignore (fork {name = name, pos = pos, pri = pri} body)) (rev prints)
    1.77 +        end
    1.78    | NONE => raise Fail (unregistered exec_id));
    1.79  
    1.80