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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/cm/main/slave.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/main/slave.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 480 - (view) (download)

1 : blume 480 (*
2 :     * This module implements the slave-side of the master-slave protocol used
3 :     * for parallel make.
4 :     *
5 :     * Copyright (c) 1999 by Lucent Bell Laboratories
6 :     *
7 :     * author: Matthias Blume (blume@cs.princeton.edu)
8 :     *)
9 :     local
10 :     structure DG = DependencyGraph
11 :     in
12 :     structure Slave = struct
13 :    
14 :     fun slave { pcmode, my_archos, parse, sbtrav, make } = let
15 :    
16 :     val dbr = ref BtNames.dirbaseDefault
17 :    
18 :     fun shutdown () = OS.Process.exit OS.Process.success
19 :     fun say_ok () = Say.say ["SLAVE: ok\n"]
20 :     fun say_error () = Say.say ["SLAVE: error\n"]
21 :     fun say_pong () = Say.say ["SLAVE: pong\n"]
22 :    
23 :     fun path (s, pcmode) = SrcPath.fromDescr pcmode s
24 :    
25 :     fun chDir d =
26 :     OS.FileSys.chDir (SrcPath.osstring (path (d, pcmode)))
27 :    
28 :     fun waitForStart () = let
29 :     val line = TextIO.inputLine TextIO.stdIn
30 :     in
31 :     if line = "" then shutdown ()
32 :     else case String.tokens Char.isSpace line of
33 :     ["cd", d] => (chDir d; say_ok (); waitForStart ())
34 :     | ["cm", archos, f] => do_cm (archos, f)
35 :     | ["cmb", archos, f] => do_cmb (archos, f)
36 :     | ["ping"] => (say_pong (); waitForStart ())
37 :     | ["finish"] => (say_ok (); waitForStart ())
38 :     | ["dirbase", db] =>
39 :     (say_ok (); dbr := db; waitForStart ())
40 :     | ["shutdown"] => shutdown ()
41 :     | _ => (say_error (); waitForStart ())
42 :     end handle _ => (say_error (); waitForStart ())
43 :    
44 :     and do_cmb (archos, f) = let
45 :     val slave = CMBSlave.slave make
46 :     in
47 :     case slave archos (!dbr, f) of
48 :     NONE => (say_error (); waitForStart ())
49 :     | SOME (g, trav, cmb_pcmode) => let
50 :     val _ = say_ok ()
51 :     val index = Reachable.snodeMap g
52 :     in
53 :     workLoop (index, trav, cmb_pcmode)
54 :     end
55 :     end handle _ => (say_error (); waitForStart ())
56 :    
57 :     and do_cm (archos, f) =
58 :     if archos <> my_archos then (say_error (); waitForStart ())
59 :     else let
60 :     val p = path (f, pcmode)
61 :     in
62 :     case parse p of
63 :     NONE => (say_error (); waitForStart ())
64 :     | SOME (g, gp) => let
65 :     val _ = say_ok ()
66 :     val index = Reachable.snodeMap g
67 :     val trav = sbtrav () gp
68 :     fun trav' sbn = isSome (trav sbn)
69 :     in
70 :     workLoop (index, trav', pcmode)
71 :     end
72 :     end handle _ => (say_error (); waitForStart ())
73 :    
74 :     and workLoop (index, trav, pcmode) = let
75 :     fun loop () = let
76 :     val line = TextIO.inputLine TextIO.stdIn
77 :     in
78 :     if line = "" then shutdown ()
79 :     else case String.tokens Char.isSpace line of
80 :     ["cd", d] => (chDir d; say_ok (); loop ())
81 :     | ["compile", f] => let
82 :     val p = path (f, pcmode)
83 :     in
84 :     case SrcPathMap.find (index, p) of
85 :     NONE => (say_error (); loop ())
86 :     | SOME sn => let
87 :     val sbn = DG.SB_SNODE sn
88 :     in
89 :     if trav sbn then (say_ok (); loop ())
90 :     else (say_error (); loop ())
91 :     end
92 :     end
93 :     | ["cm", archos, f] => do_cm (archos, f)
94 :     | ["cmb", archos, f] => do_cmb (archos, f)
95 :     | ["finish"] => (say_ok (); waitForStart ())
96 :     | ["dirbase", db] =>
97 :     (say_ok (); dbr := db; waitForStart ())
98 :     | ["ping"] => (say_pong (); loop ())
99 :     | ["shutdown"] => shutdown ()
100 :     | _ => (say_error (); loop ())
101 :     end handle _ => (say_error (); loop ())
102 :     in
103 :     loop ()
104 :     end
105 :     in
106 :     ignore (Signals.setHandler (Signals.sigINT, Signals.IGNORE));
107 :     say_ok (); (* announce readiness *)
108 :     waitForStart () handle _ => ();
109 :     OS.Process.exit OS.Process.failure
110 :     end
111 :     end
112 :     end

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