Commits

camlspotter  committed c4d90fc

added systhreads/thread.ml, newly svn handled module

  • Participants
  • Parent commits 2f3f8b6
  • Branches ocaml-svn-trunk

Comments (0)

Files changed (2)

 ^otherlibs/labltk/(labltk|camltk)/.*\.(ml|mli)$
 ^otherlibs/labltk/labltk/\.depend$
 
-^asmcomp/arch\.ml$
-^asmcomp/emit\.ml$
-^asmcomp/proc\.ml$
-^asmcomp/reload\.ml$
-^asmcomp/scheduling\.ml$
-^asmcomp/selection\.ml$
-^asmrun/alloc\.c$
-^asmrun/array\.c$
-^asmrun/callback\.c$
-^asmrun/compact\.c$
-^asmrun/compare\.c$
-^asmrun/custom\.c$
-^asmrun/dynlink\.c$
-^asmrun/extern\.c$
-^asmrun/finalise\.c$
-^asmrun/floats\.c$
-^asmrun/freelist\.c$
-^asmrun/gc_ctrl\.c$
-^asmrun/globroots\.c$
-^asmrun/hash\.c$
-^asmrun/intern\.c$
-^asmrun/ints\.c$
-^asmrun/io\.c$
-^asmrun/lexing\.c$
-^asmrun/main\.c$
-^asmrun/major_gc\.c$
-^asmrun/md5\.c$
-^asmrun/memory\.c$
-^asmrun/meta\.c$
-^asmrun/minor_gc\.c$
-^asmrun/misc\.c$
-^asmrun/obj\.c$
-^asmrun/parsing\.c$
-^asmrun/printexc\.c$
-^asmrun/signals\.c$
-^asmrun/str\.c$
-^asmrun/sys\.c$
-^asmrun/terminfo\.c$
-^asmrun/unix\.c$
-^asmrun/weak\.c$
-
-^build/ocamlbuild_mixed_mode$
-^bytecomp/opcodes\.ml$
-^bytecomp/runtimedef\.ml$
-^byterun/jumptbl\.h$
-^byterun/ld\.conf$
-^byterun/ocamlrun$
-^byterun/primitives$
-^byterun/prims\.c$
-^byterun/version\.h$
-^config/Makefile$
-^config/config\.sh$
-^config/m\.h$
-^config/s\.h$
-^debugger/lexer\.ml$
-^debugger/ocamldebug$
-^debugger/parser\.ml$
-^debugger/parser\.mli$
-^expunge$
-^lex/lexer\.ml$
-^lex/ocamllex$
-^lex/ocamllex\.opt$
-^lex/parser\.ml$
-^lex/parser\.mli$
-^myocamlbuild_config\.ml$
-^ocaml$
-^ocamlc$
-^ocamlc\.opt$
-^ocamlcomp\.sh$
-^ocamlcompopt\.sh$
-^ocamldoc/ocamldoc$
-^ocamldoc/ocamldoc\.opt$
-^ocamldoc/odoc_lexer\.ml$
-^ocamldoc/odoc_ocamlhtml\.ml$
-^ocamldoc/odoc_parser\.ml$
-^ocamldoc/odoc_parser\.mli$
-^ocamldoc/odoc_see_lexer\.ml$
-^ocamldoc/odoc_text_lexer\.ml$
-^ocamldoc/odoc_text_parser\.ml$
-^ocamldoc/odoc_text_parser\.mli$
-^ocamlopt$
-^ocamlopt\.opt$
-^otherlibs/dynlink/extract_crc$
-^otherlibs/labltk/browser/dummy\.mli$
-^otherlibs/labltk/browser/ocamlbrowser$
-^otherlibs/labltk/camltk/\.depend$
-^otherlibs/labltk/compiler/copyright\.ml$
-^otherlibs/labltk/compiler/lexer\.ml$
-^otherlibs/labltk/compiler/parser\.ml$
-^otherlibs/labltk/compiler/parser\.mli$
-^otherlibs/labltk/compiler/pp$
-^otherlibs/labltk/compiler/pplex\.ml$
-^otherlibs/labltk/compiler/ppyac\.ml$
-^otherlibs/labltk/compiler/ppyac\.mli$
-^otherlibs/labltk/compiler/tkcompiler$
-^otherlibs/labltk/lib/labltk$
-^otherlibs/labltk/lib/labltktop$
-^otherlibs/systhreads/thread\.ml$
-^otherlibs/threads/marshal\.mli$
-^otherlibs/threads/pervasives\.mli$
-^otherlibs/threads/unix\.mli$
-^parsing/lexer\.ml$
-^parsing/linenum\.ml$
-^parsing/parser\.ml$
-^parsing/parser\.mli$
-^stdlib/caml$
-^stdlib/camlheader$
-^stdlib/camlheader_ur$
-^stdlib/sys\.ml$
-^tools/addlabels$
-^tools/cvt_emit$
-^tools/cvt_emit\.ml$
-^tools/dumpobj$
-^tools/lexer301\.ml$
-^tools/myocamlbuild_config\.ml$
-^tools/ocamlcp$
-^tools/ocamldep$
-^tools/ocamldep\.opt$
-^tools/ocamlmklib$
-^tools/ocamlmklib\.ml$
-^tools/ocamlmktop$
-^tools/ocamlprof$
-^tools/opnames\.ml$
-^tools/scrapelabels$
-^utils/config\.ml$
-^yacc/ocamlyacc$
-^yacc/version\.h$

File otherlibs/systhreads/thread.ml

+(***********************************************************************)
+(*                                                                     *)
+(*                         Objective Caml                              *)
+(*                                                                     *)
+(*  Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt   *)
+(*                                                                     *)
+(*  Copyright 1996 Institut National de Recherche en Informatique et   *)
+(*  en Automatique.  All rights reserved.  This file is distributed    *)
+(*  under the terms of the GNU Library General Public License, with    *)
+(*  the special exception on linking described in file ../../LICENSE.  *)
+(*                                                                     *)
+(***********************************************************************)
+
+(* $Id: thread_posix.ml 9547 2010-01-22 12:48:24Z doligez $ *)
+
+(* User-level threads *)
+
+type t
+
+external thread_initialize : unit -> unit = "caml_thread_initialize"
+external thread_new : (unit -> unit) -> t = "caml_thread_new"
+external thread_uncaught_exception : exn -> unit =
+            "caml_thread_uncaught_exception"
+
+external yield : unit -> unit = "caml_thread_yield"
+external self : unit -> t = "caml_thread_self"
+external id : t -> int = "caml_thread_id"
+external join : t -> unit = "caml_thread_join"
+external exit : unit -> unit = "caml_thread_exit"
+
+(* For new, make sure the function passed to thread_new never
+   raises an exception. *)
+
+let create fn arg =
+  thread_new
+    (fun () ->
+      try
+        fn arg; ()
+      with exn ->
+             flush stdout; flush stderr;
+             thread_uncaught_exception exn)
+
+(* Thread.kill is currently not implemented due to problems with
+   cleanup handlers on several platforms *)
+
+let kill th = invalid_arg "Thread.kill: not implemented"
+
+(* Preemption *)
+
+let preempt signal = yield()
+
+(* Initialization of the scheduler *)
+
+let preempt_signal =
+  match Sys.os_type with
+  | "Win32" -> Sys.sigterm
+  | _       -> Sys.sigvtalrm
+
+let _ =
+  ignore(Sys.signal preempt_signal (Sys.Signal_handle preempt));
+  thread_initialize()
+
+(* Wait functions *)
+
+let delay time = ignore(Unix.select [] [] [] time)
+
+let wait_read fd = ()
+let wait_write fd = ()
+
+let wait_timed_read fd d =
+  match Unix.select [fd] [] [] d with ([], _, _) -> false | (_, _, _) -> true
+let wait_timed_write fd d =
+  match Unix.select [] [fd] [] d with (_, [], _) -> false | (_, _, _) -> true
+let select = Unix.select
+
+let wait_pid p = Unix.waitpid [] p
+
+external sigmask : Unix.sigprocmask_command -> int list -> int list = "caml_thread_sigmask"
+external wait_signal : int list -> int = "caml_wait_signal"