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/trunk/src/cm/concur/unix-servers.sml
ViewVC logotype

Diff of /sml/trunk/src/cm/concur/unix-servers.sml

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

revision 484, Thu Nov 18 08:46:16 1999 UTC revision 645, Mon May 15 07:17:30 2000 UTC
# Line 36  Line 36 
36      end      end
37      val enabled = ref false      val enabled = ref false
38    
39        val idle = ref ([]: server list)
40        val someIdle = ref (Concur.pcond ())
41    
42      local      local
43          val nservers = ref 0          val all = ref (IntMap.empty: server IntMap.map)
44          val all = ref (IntRedBlackMap.empty: server IntRedBlackMap.map)          fun nservers () = IntMap.numItems (!all)
45      in      in
46          fun noServers () = !nservers = 0          fun allIdle () = length (!idle) = nservers ()
47          fun allServers () = IntRedBlackMap.listItems (!all)          fun noServers () = nservers () = 0
48            fun allServers () = IntMap.listItems (!all)
49          fun addServer s = let          fun addServer s = let
50              val ns = !nservers              val ns = nservers ()
         in  
             nservers := ns + 1;  
             all := IntRedBlackMap.insert (!all, servId s, s)  
         end  
         fun delServer s = let  
             val ns = !nservers - 1  
51          in          in
52              all := #1 (IntRedBlackMap.remove (!all, servId s));              all := IntMap.insert (!all, servId s, s)
             nservers := ns  
53          end          end
54            fun delServer s =
55                (all := #1 (IntMap.remove (!all, servId s));
56                 (* If this was the last server we need to wake up
57                  * everyone who is currently waiting to grab a server.
58                  * The "grab"-loop will then gracefully fail and
59                  * not cause a deadlock. *)
60                 if noServers () then
61                     (Say.dsay ["No more servers -> back to sequential mode.\n"];
62                      Concur.signal (!someIdle))
63                 else ())
64      end      end
65    
     val idle = ref ([]: server list)  
     val someIdle = ref (Concur.pcond ())  
   
66      (* This really shouldn't be here, but putting it into SrcPath would      (* This really shouldn't be here, but putting it into SrcPath would
67       * create a dependency cycle.  Some better structuring will fix this. *)       * create a dependency cycle.  Some better structuring will fix this. *)
68      fun isAbsoluteDescr d =      fun isAbsoluteDescr d =
# Line 70  Line 74 
74              NONE => n              NONE => n
75            | SOME f => if isAbsoluteDescr n then f n else n            | SOME f => if isAbsoluteDescr n then f n else n
76    
77        (* protect some code segment from sigPIPE signals... *)
78      fun pprotect work = let      fun pprotect work = let
79          val pipe = UnixSignals.sigPIPE          val pipe = UnixSignals.sigPIPE
80          fun disable () = Signals.setHandler (pipe, Signals.IGNORE)          fun disable () = Signals.setHandler (pipe, Signals.IGNORE)
# Line 79  Line 84 
84                           work = fn _ => work (), cleanup = fn _ => () }                           work = fn _ => work (), cleanup = fn _ => () }
85      end      end
86    
87        (* Send a message to a slave. This must be sigPIPE-protected. *)
88      fun send (s, msg) = let      fun send (s, msg) = let
89          val outs = servOuts s          val outs = servOuts s
90      in      in
# Line 103  Line 109 
109      (* Grab an idle server; wait if necessary; reinitialize condition      (* Grab an idle server; wait if necessary; reinitialize condition
110       * if taking the only server. *)       * if taking the only server. *)
111      fun grab () =      fun grab () =
112          case !idle of          (* We need to check the following every time (at least the
113             * "noServers" part) because it might be that all servers
114             * have meanwhile gone away for some reason (crashed, etc.). *)
115            if not (!enabled) orelse noServers () then NONE
116            else case !idle of
117              [] => (Concur.wait (!someIdle); grab ())              [] => (Concur.wait (!someIdle); grab ())
118            | [only] =>            | [only] =>
119                  (Say.dsay ["Scheduler: taking last idle slave (",                  (Say.dsay ["Scheduler: taking last idle slave (",
120                             servName only, ").\n"];                             servName only, ").\n"];
121                   idle := [];                   idle := [];
122                   someIdle := Concur.pcond ();                   someIdle := Concur.pcond ();
123                   only)                   SOME only)
124            | first :: more => let            | first :: more => let
125                  fun best (b, [], rest) = (b, rest)                  fun best (b, [], rest) = (b, rest)
126                    | best (b, s :: r, rest) = let                    | best (b, s :: r, rest) = let
# Line 126  Line 136 
136                            servName b, ").\n"];                            servName b, ").\n"];
137                  idle := rest;                  idle := rest;
138                  show_idle ();                  show_idle ();
139                  b                  SOME b
140              end              end
141    
142      fun wait_status (s, echo) = let      fun wait_status (s, echo) = let
# Line 148  Line 158 
158                    | _ => "crashed"                    | _ => "crashed"
159          in          in
160              decommission s;              decommission s;
161              Say.say ["! Slave ", name, " has ", what, ".\n"];              Say.say ["[!Slave ", name, " has ", what, ".]\n"];
162              delServer s              delServer s
163          end          end
164    
# Line 256  Line 266 
266      end      end
267    
268      fun compile p =      fun compile p =
269          if not (!enabled) orelse noServers () then false          case grab () of
270          else let              NONE => false
271              val s = grab ()            | SOME s => let
272              val f = fname (p, s)              val f = fname (p, s)
273          in          in
274              Say.vsay ["[(", servName s, "): compiling ", f, "]\n"];              Say.vsay ["[(", servName s, "): compiling ", f, "]\n"];
# Line 307  Line 317 
317               ignore (wait_status (s, false)))               ignore (wait_status (s, false)))
318      in      in
319          startAll st          startAll st
320        end
321    
322        fun cmb_new { archos } = let
323            fun st s =
324                (send (s, concat ["cmb ", archos, "\n"]);
325                 ignore (wait_status (s, false)))
326        in
327            startAll st
328      end      end
329    
330      fun dirbase db = let      fun dirbase db = let

Legend:
Removed from v.484  
changed lines
  Added in v.645

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