1 (* Copyright (C
) 2006-2006 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
4 * MLton is released under a BSD
-style license
.
5 * See the file MLton
-LICENSE for details
.
12 val make
: (unit
-> 'a
) -> 'a t
13 val use
: 'a t
* ('a
-> 'b
) -> 'b
16 datatype 'a t
= T
of {more
: unit
-> 'a
,
18 staticIsInUse
: bool ref
}
20 fun make f
= T
{more
= f
,
22 staticIsInUse
= ref
false}
24 fun use (T
{more
, static
, staticIsInUse
}, f
) =
26 val () = Primitive
.MLton
.Thread
.atomicBegin ()
27 val b
= ! staticIsInUse
30 (Primitive
.MLton
.Thread
.atomicEnd ();
33 (staticIsInUse
:= true;
34 Primitive
.MLton
.Thread
.atomicEnd ();
37 DynamicWind
.wind (fn () => f d
,
38 fn () => if b
then () else staticIsInUse
:= false)