1. Dmitry Grebeniuk
  2. parvel

Commits

Dmitry Grebeniuk  committed 4b73a80

added Parvel.{register,run}_program[s] (incomplete, for one process now), IO.join

  • Participants
  • Parent commits 1bc1c22
  • Branches default

Comments (0)

Files changed (6)

File parvel.ml

View file
  • Ignore whitespace
+type program_exec_type =
+  [= `Main | `Per_process ]
+;
+
 (*
 module type COUNTER
  =
     ;
 
 
+    (* registering and running programs *)
+
+    value progs_queue = Queue.create ()
+    ;
+
+    value register_program prog_exec_type prog_name prog_code =
+      Queue.push (prog_exec_type, prog_name, prog_code) progs_queue
+    ;
+
+    value run_programs_pred pred () =
+      let (_names, codes) =
+        Queue.fold
+          (fun ((acc_n, acc_c) as accs) (pet, pn, pc) ->
+             if pred pet
+             then ([pn :: acc_n], [pc :: acc_c])
+             else accs
+          )
+          ([], [])
+          progs_queue
+      in
+        IO.join (List.map (fun c -> c ()) codes)
+    ;
+
+    value run_programs () =
+      run_programs_pred (fun _ -> True) ()
+    ;
+
+
+
   end
 ;

File parvel.mli

View file
  • Ignore whitespace
    'o -- тип отправляемых сообщений.
  *)
 
+
+(* parameter for [register_program]:
+     `Main -- only one instance of this program will run
+     `Per_process -- each worker process will run this code
+     will be added possibly:
+     `Per_host -- either master or the first worker on this host
+       will run this code
+     `Per_cpu -- ... on this CPU core ...
+ *)
+
+type program_exec_type =
+  [= `Main | `Per_process ]
+;
+
+
 (* Всё, что зависит от конкретной реализации ввода-вывода,
    закатываем в функтор: *)
 
  :
   sig
 
+    (* registering programs for execution in main / workers *)
+
+    (* [register_program exec_type program_name program_body]
+       registers program for later execution
+     *)
+
+    value register_program :
+      program_exec_type ->
+      string ->
+      (unit -> IO.m unit) ->
+      unit
+    ;
+
+    value run_programs : unit -> IO.m unit
+    ;
+
+    (*********************************************************)
+
     type process_command_req =
       [= `Shutdown ]
     ;

File parvel_IO.ml

View file
  • Ignore whitespace
 
 
 value run_and_ignore_result : m unit -> unit = Lwt.ignore_result;
+value join : list (m unit) -> m unit = Lwt.join;
 
 value fprintf outch fmt = Printf.ksprintf (fun s -> write outch s) fmt;
 

File parvel_types.ml

View file
  • Ignore whitespace
     ;
 
     value run_and_ignore_result : m unit -> unit;
+    value join : list (m unit) -> m unit;
 
     value printf : format4 'a unit string (m unit) -> 'a;
 

File run.bat

View file
  • Ignore whitespace
-@call c:\overbld\ocaml\set-vars.bat
+@call d:\overbld\ocaml\set-vars.bat
 @bash ./run.sh

File tests.ml

View file
  • Ignore whitespace
 
 
 
-value io_main () =
+value () = P.register_program `Main "tests/io_main" & fun () ->
   P.create_server_group () >>= fun servg ->
 (*
   P.create_process servg (loop do_something) >>= fun serv ->
 
 value main () =
   try
-    match IO.runIO & io_main () with
+    match IO.runIO & P.run_programs () with
     [ `Ok () -> ()
     | `Error e -> printf "main: %s\n%!" & Printexc.to_string e
     ]