Mercurial > projects > mde
comparison mde/setup/Init.d @ 89:97e6dce08037
Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Mon, 29 Sep 2008 18:27:17 +0100 |
parents | 01f4f5f1acc9 |
children | 4d5d53e4f881 |
comparison
equal
deleted
inserted
replaced
88:01f4f5f1acc9 | 89:97e6dce08037 |
---|---|
211 | 211 |
212 // Calculate reverse dependencies of stages: | 212 // Calculate reverse dependencies of stages: |
213 foreach (key,stage_p; stages) | 213 foreach (key,stage_p; stages) |
214 foreach (name; stage_p.depends) | 214 foreach (name; stage_p.depends) |
215 stages[name].rdepends ~= key; | 215 stages[name].rdepends ~= key; |
216 if (miscOpts.numThreads < 1 || miscOpts.numThreads > 64) // limit to a sensible number of threads | |
217 miscOpts.set!(int)("numThreads", 4); // FIXME enforce limit in Options | |
218 | 216 |
219 runStages!(true); // startup delegates | 217 runStages!(true); // startup delegates |
220 | 218 |
221 debug logger.trace ("Init: done"); | 219 debug logger.trace ("Init: done"); |
222 } | 220 } |
256 v.state = StageState.INACTIVE; | 254 v.state = StageState.INACTIVE; |
257 } | 255 } |
258 } | 256 } |
259 } | 257 } |
260 auto toRunIt = toRun.iterator; | 258 auto toRunIt = toRun.iterator; |
261 int numWorking = miscOpts.numThreads; | 259 // Counts number of active threads, and before threads are started is number to use: |
260 size_t numWorking = (toRun.size < miscOpts.maxThreads) ? toRun.size : miscOpts.maxThreads; | |
262 enum STATE { WORKING = 0, DONE = 1, ABORT = 2 } | 261 enum STATE { WORKING = 0, DONE = 1, ABORT = 2 } |
263 STATE doneInit = STATE.WORKING; | 262 STATE doneInit = STATE.WORKING; |
264 Mutex toRunM = new Mutex; // synchronization on toRun, numWorking | 263 Mutex toRunM = new Mutex; // synchronization on toRun, numWorking |
265 Condition toRunC = new Condition(toRunM); // used by threads waiting for remaining stages' dependencies to be met | 264 Condition toRunC = new Condition(toRunM); // used by threads waiting for remaining stages' dependencies to be met |
266 | 265 |
357 doneInit |= STATE.DONE; // allow other threads a faster exit | 356 doneInit |= STATE.DONE; // allow other threads a faster exit |
358 toRunC.notifyAll(); // Most likely if we're exiting, we should make sure others aren't waiting. | 357 toRunC.notifyAll(); // Most likely if we're exiting, we should make sure others aren't waiting. |
359 return; | 358 return; |
360 } | 359 } |
361 | 360 |
362 // Start miscOpts.NumThreads - 1 threads: | 361 // Start min(miscOpts.maxThreads,toRun.size)-1 threads: |
363 try { | 362 try { |
364 ThreadGroup g = new ThreadGroup; | 363 ThreadGroup g = new ThreadGroup; |
365 for (int i = miscOpts.numThreads; i > 1; --i) | 364 for (size_t i = numWorking; i > 1; --i) |
366 g.create (&initThreadFct); | 365 g.create (&initThreadFct); |
367 initThreadFct(); // also run in current thread | 366 initThreadFct(); // also run in current thread |
368 g.joinAll (false); // don't rethrow exceptions - there SHOULD NOT be any | 367 g.joinAll (false); // don't rethrow exceptions - there SHOULD NOT be any |
369 } catch (ThreadException e) { | 368 } catch (ThreadException e) { |
370 logger.error ("Exception while using threads: "~e.msg); | 369 logger.error ("Exception while using threads: "~e.msg); |
444 // Stuff normally done in Init.this(): | 443 // Stuff normally done in Init.this(): |
445 // Calculate reverse dependencies of stages: | 444 // Calculate reverse dependencies of stages: |
446 foreach (key,stage_p; stages) | 445 foreach (key,stage_p; stages) |
447 foreach (name; stage_p.depends) | 446 foreach (name; stage_p.depends) |
448 stages[name].rdepends ~= key; | 447 stages[name].rdepends ~= key; |
449 if (miscOpts.numThreads < 1 || miscOpts.numThreads > 64) // limit to a sensible number of threads | 448 auto realNumThreads = miscOpts.numThreads; |
450 miscOpts.set!(int)("numThreads", 4); // FIXME enforce limit in Options | 449 miscOpts.set!(int)("numThreads", 4); // force 4 threads for unittest |
451 | 450 |
452 | 451 |
453 // Run the above. | 452 // Run the above. |
454 runStages!(true); | 453 runStages!(true); |
455 assert (init1); | 454 assert (init1); |
484 assert (!a1, "runStages didn't throw"); | 483 assert (!a1, "runStages didn't throw"); |
485 assert (init1); // s1.init should run first; s2.init may or may not get run | 484 assert (init1); // s1.init should run first; s2.init may or may not get run |
486 assert (stages[toStageName("stg3")].state == cast(StageState)7); // set by the exception | 485 assert (stages[toStageName("stg3")].state == cast(StageState)7); // set by the exception |
487 | 486 |
488 stages = realInit; // restore the real init stages | 487 stages = realInit; // restore the real init stages |
488 miscOpts.set!(int)("numThreads", realNumThreads); | |
489 logger.info ("Unittest complete."); | 489 logger.info ("Unittest complete."); |
490 } | 490 } |
491 } | 491 } |