Mercurial > projects > mde
comparison mde/setup/Init.d @ 95:2a364c7d82c9
Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Fixed a minor bug where layouts with the same id but without shared alignments would be messed up.
Tracked down the "nothing trawn until a resize" bug (see jobs.txt).
If widgets throw during creation they're now replaced by debug widgets.
Function pointers are converted to delegates using a safer method.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 06 Nov 2008 11:07:18 +0000 |
parents | 9520cc0448e5 |
children | 49e7cfed4b34 |
comparison
equal
deleted
inserted
replaced
94:9520cc0448e5 | 95:2a364c7d82c9 |
---|---|
260 enum STATE { WORKING = 0, DONE = 1, ABORT = 2 } | 260 enum STATE { WORKING = 0, DONE = 1, ABORT = 2 } |
261 STATE doneInit = STATE.WORKING; | 261 STATE doneInit = STATE.WORKING; |
262 Mutex toRunM = new Mutex; // synchronization on toRun, numWorking | 262 Mutex toRunM = new Mutex; // synchronization on toRun, numWorking |
263 Condition toRunC = new Condition(toRunM); // used by threads waiting for remaining stages' dependencies to be met | 263 Condition toRunC = new Condition(toRunM); // used by threads waiting for remaining stages' dependencies to be met |
264 | 264 |
265 /* initThreadFct is now in a class to allow reliably identifying whcich instance is run in the main thread. | |
266 * The main thread gets index 0, other threads indexes 2,3,4,etc. (there is no 1). */ | |
267 class InitStageThread : Thread { | |
268 this (int n) { | |
269 debug threadNum = n; | |
270 super (&initThreadFct); | |
271 } | |
272 debug int threadNum; | |
265 /* This is a threadable member function to run init stages. | 273 /* This is a threadable member function to run init stages. |
266 * Operation follows: | 274 * Operation follows: |
267 * 1 Look for a stage to run: | 275 * 1 Look for a stage to run: |
268 * if found: | 276 * if found: |
269 * notify waiting threads work may be available | 277 * notify waiting threads work may be available |
327 | 335 |
328 // Do a job: | 336 // Do a job: |
329 try { | 337 try { |
330 // FIXME - old stage start&finish trace messages - we don't have a name! | 338 // FIXME - old stage start&finish trace messages - we don't have a name! |
331 static if (startup) { | 339 static if (startup) { |
332 debug logger.trace ("InitStage {}: starting init", stage.name); | 340 debug logger.trace ("({}) InitStage {}: starting init", threadNum, stage.name); |
333 stage.state = (*stage).init(); // init is a property of a pointer (oh no!) | 341 stage.state = (*stage).init(); // init is a property of a pointer (oh no!) |
334 } else { | 342 } else { |
335 debug logger.trace ("InitStage {}: starting cleanup", stage.name); | 343 debug logger.trace ("({}) InitStage {}: starting cleanup", threadNum, stage.name); |
336 stage.state = stage.cleanup(); | 344 stage.state = stage.cleanup(); |
337 } | 345 } |
338 debug logger.trace ("InitStage {}: completed; state: {}", stage.name, stage.state); | 346 debug logger.trace ("({}) InitStage {}: completed; state: {}", threadNum, stage.name, stage.state); |
339 } catch (InitStageException e) { | 347 } catch (InitStageException e) { |
340 debug logger.trace ("InitStage {}: failed: "~e.msg, stage.name); | 348 debug logger.trace ("({}) InitStage {}: failed: "~e.msg, threadNum, stage.name); |
341 stage.state = e.state; | 349 stage.state = e.state; |
342 doneInit = STATE.ABORT; | 350 doneInit = STATE.ABORT; |
343 break threadLoop; | 351 break threadLoop; |
344 } catch (Exception e) { | 352 } catch (Exception e) { |
345 debug logger.trace ("InitStage {}: failed: "~e.msg, stage.name); | 353 debug logger.trace ("({}) InitStage {}: failed: "~e.msg, threadNum, stage.name); |
346 doneInit = STATE.ABORT; | 354 doneInit = STATE.ABORT; |
347 break threadLoop; | 355 break threadLoop; |
348 } | 356 } |
349 } | 357 } |
350 } catch (Exception e) { | 358 } catch (Exception e) { |
353 } | 361 } |
354 doneInit |= STATE.DONE; // allow other threads a faster exit | 362 doneInit |= STATE.DONE; // allow other threads a faster exit |
355 toRunC.notifyAll(); // Most likely if we're exiting, we should make sure others aren't waiting. | 363 toRunC.notifyAll(); // Most likely if we're exiting, we should make sure others aren't waiting. |
356 return; | 364 return; |
357 } | 365 } |
366 } | |
358 | 367 |
359 // Start min(miscOpts.maxThreads,toRun.size)-1 threads: | 368 // Start min(miscOpts.maxThreads,toRun.size)-1 threads: |
360 try { | 369 try { |
361 ThreadGroup g = new ThreadGroup; | 370 ThreadGroup g = new ThreadGroup; |
362 for (size_t i = numWorking; i > 1; --i) | 371 InitStageThread x; |
363 g.create (&initThreadFct); | 372 for (size_t i = numWorking; i > 1; --i) { |
364 initThreadFct(); // also run in current thread | 373 //g.create (&initThreadFct); |
374 x = new InitStageThread (i); | |
375 x.start; | |
376 g.add (x); | |
377 } | |
378 x = new InitStageThread (0); | |
379 x.initThreadFct(); // also run in current thread | |
365 g.joinAll (false); // don't rethrow exceptions - there SHOULD NOT be any | 380 g.joinAll (false); // don't rethrow exceptions - there SHOULD NOT be any |
366 } catch (ThreadException e) { | 381 } catch (ThreadException e) { |
367 logger.error ("Exception while using threads: "~e.msg); | 382 logger.error ("Exception while using threads: "~e.msg); |
368 logger.error ("Disabling threads and attempting to continue."); | 383 logger.error ("Disabling threads and attempting to continue."); |
369 miscOpts.set!(int)("NumThreads", 1); // count includes current thread | 384 miscOpts.set!(int)("NumThreads", 1); // count includes current thread |
370 initThreadFct(); // try with just this thread | 385 auto x = new InitStageThread (0); |
386 x.initThreadFct(); // try with just this thread | |
371 } // any other exception will be caught in main() and abort program | 387 } // any other exception will be caught in main() and abort program |
372 | 388 |
373 if (doneInit & STATE.ABORT) | 389 if (doneInit & STATE.ABORT) |
374 throw new InitException ("An init/cleanup function failed (see above message(s))"); | 390 throw new InitException ("An init/cleanup function failed (see above message(s))"); |
375 | 391 |