Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/branches/SMLNJ/src/cm/util/safeio.sml
ViewVC logotype

Diff of /sml/branches/SMLNJ/src/cm/util/safeio.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 629, Wed Apr 26 04:06:41 2000 UTC revision 630, Wed Apr 26 18:40:56 2000 UTC
# Line 7  Line 7 
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
20    
21      structure S = Signals      structure S = Signals
     val callcc = SMLofNJ.Cont.callcc  
     val throw = SMLofNJ.Cont.throw  
22    
23      fun perform { openIt, closeIt, work, cleanup } = let      fun perform { openIt, closeIt, work, cleanup } = let
24          val oh = S.inqHandler S.sigINT          val oh = S.inqHandler S.sigINT
# Line 26  Line 26 
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.629  
changed lines
  Added in v.630

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0