SCM Repository
[smlnj] Diff of /sml/trunk/src/cm/util/safeio.sml
Diff of /sml/trunk/src/cm/util/safeio.sml
Parent Directory
|
Revision Log
|
Patch
7 |
*) |
*) |
8 |
signature SAFEIO = sig |
signature SAFEIO = sig |
9 |
|
|
10 |
|
(* the cleanup function is being told whether it is called because |
11 |
|
* of an interrupt *) |
12 |
val perform : |
val perform : |
13 |
{ openIt : unit -> 'a, |
{ openIt : unit -> 'a, |
14 |
closeIt : 'a -> unit, |
closeIt : 'a -> unit, |
15 |
work : 'a -> 'b, |
work : 'a -> 'b, |
16 |
cleanup : unit -> unit } -> 'b |
cleanup : bool -> unit } -> 'b |
17 |
end |
end |
18 |
|
|
19 |
structure SafeIO :> SAFEIO = struct |
structure SafeIO :> SAFEIO = struct |
26 |
val _ = S.maskSignals intMask |
val _ = S.maskSignals intMask |
27 |
val s = openIt () |
val s = openIt () |
28 |
handle e => (S.unmaskSignals intMask; |
handle e => (S.unmaskSignals intMask; |
29 |
cleanup (); |
cleanup false; |
30 |
raise e) |
raise e) |
31 |
fun reset () = (closeIt s; ignore (S.setHandler (S.sigINT, oh))) |
fun reset () = (closeIt s; ignore (S.setHandler (S.sigINT, oh))) |
32 |
fun handler arg = |
fun handler arg = |
33 |
(reset (); |
(reset (); |
34 |
cleanup (); |
cleanup true; |
35 |
case oh of |
case oh of |
36 |
S.HANDLER h => h arg |
S.HANDLER h => h arg |
37 |
| _ => OS.Process.exit OS.Process.failure) |
| _ => OS.Process.exit OS.Process.failure) |
38 |
in |
in |
39 |
(S.overrideHandler (S.sigINT, S.HANDLER handler); |
(S.overrideHandler (S.sigINT, S.HANDLER handler); |
40 |
S.unmaskSignals intMask; |
S.unmaskSignals intMask; |
41 |
(work s handle e => (reset (); cleanup (); raise e)) |
(work s handle e => (reset (); cleanup false; raise e)) |
42 |
before reset ()) |
before reset ()) |
43 |
end |
end |
44 |
end |
end |
|
Legend:
Removed from v.367 |
|
changed lines |
|
Added in v.651 |
|
|