src/Pure/ML-Systems/unsynchronized.ML
author wenzelm
Sat Nov 27 16:29:53 2010 +0100 (2010-11-27 ago)
changeset 40748 591b6778d076
parent 39616 8052101883c3
permissions -rw-r--r--
removed bash from ML system bootstrap, and past the Secure ML barrier;
wenzelm@32737
     1
(*  Title:      Pure/ML-Systems/unsynchronized.ML
wenzelm@32737
     2
    Author:     Makarius
wenzelm@32737
     3
wenzelm@32737
     4
Raw ML references as unsynchronized state variables.
wenzelm@32737
     5
*)
wenzelm@32737
     6
wenzelm@32737
     7
structure Unsynchronized =
wenzelm@32737
     8
struct
wenzelm@32737
     9
wenzelm@32737
    10
datatype ref = datatype ref;
wenzelm@32737
    11
wenzelm@32737
    12
val op := = op :=;
wenzelm@32737
    13
val ! = !;
wenzelm@32737
    14
wenzelm@32737
    15
fun change r f = r := f (! r);
wenzelm@32737
    16
fun change_result r f = let val (x, y) = f (! r) in r := y; x end;
wenzelm@32737
    17
wenzelm@32737
    18
fun inc i = (i := ! i + (1: int); ! i);
wenzelm@32737
    19
fun dec i = (i := ! i - (1: int); ! i);
wenzelm@32737
    20
wenzelm@39616
    21
fun setmp flag value f x =
wenzelm@39616
    22
  uninterruptible (fn restore_attributes => fn () =>
wenzelm@39616
    23
    let
wenzelm@39616
    24
      val orig_value = ! flag;
wenzelm@39616
    25
      val _ = flag := value;
wenzelm@39616
    26
      val result = Exn.capture (restore_attributes f) x;
wenzelm@39616
    27
      val _ = flag := orig_value;
wenzelm@39616
    28
    in Exn.release result end) ();
wenzelm@39616
    29
wenzelm@32737
    30
end;