Revision a3e3ff17e89e6032e7683060472cde8eab74253e authored by Damien Doligez on 19 July 2012, 14:37:16 UTC, committed by Damien Doligez on 19 July 2012, 14:37:16 UTC

git-svn-id: http://caml.inria.fr/svn/ocaml/release/4.00.0+rc1@12743 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent 7a5a8e8
Raw File
exec.ml
(***********************************************************************)
(*                                                                     *)
(*                                OCaml                                *)
(*                                                                     *)
(*          Jerome Vouillon, projet Cristal, INRIA Rocquencourt        *)
(*          OCaml port by John Malecki and Xavier Leroy                *)
(*                                                                     *)
(*  Copyright 1996 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the Q Public License version 1.0.               *)
(*                                                                     *)
(***********************************************************************)

(* $Id$ *)

(* Handling of keyboard interrupts *)

let interrupted = ref false

let is_protected = ref false

let break signum =
  if !is_protected
  then interrupted := true
  else raise Sys.Break

let _ =
  match Sys.os_type with
    "Win32" -> ()
  | _ ->
      Sys.set_signal Sys.sigint (Sys.Signal_handle break);
      Sys.set_signal Sys.sigpipe (Sys.Signal_handle (fun _ -> raise End_of_file))

let protect f =
  if !is_protected then
    f ()
  else begin
    is_protected := true;
    if not !interrupted then
       f ();
    is_protected := false;
    if !interrupted then begin interrupted := false; raise Sys.Break end
  end

let unprotect f =
  if not !is_protected then
    f ()
  else begin
    is_protected := false;
    if !interrupted then begin interrupted := false; raise Sys.Break end;
    f ();
    is_protected := true
  end
back to top