diff 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
line wrap: on
line diff
--- a/mde/setup/Init.d	Thu Oct 23 17:45:49 2008 +0100
+++ b/mde/setup/Init.d	Thu Nov 06 11:07:18 2008 +0000
@@ -262,6 +262,14 @@
         Mutex toRunM = new Mutex;       // synchronization on toRun, numWorking
         Condition toRunC = new Condition(toRunM);       // used by threads waiting for remaining stages' dependencies to be met
         
+        /* initThreadFct is now in a class to allow reliably identifying whcich instance is run in the main thread.
+         * The main thread gets index 0, other threads indexes 2,3,4,etc. (there is no 1). */
+        class InitStageThread : Thread {
+            this (int n) {
+                debug threadNum = n;
+                super (&initThreadFct);
+            }
+            debug int threadNum;
         /* This is a threadable member function to run init stages.
          * Operation follows:
          * 1 Look for a stage to run:
@@ -329,20 +337,20 @@
                     try {
                         // FIXME - old stage start&finish trace messages - we don't have a name!
                         static if (startup) {
-                            debug logger.trace ("InitStage {}: starting init", stage.name);
+                            debug logger.trace ("({}) InitStage {}: starting init", threadNum, stage.name);
                             stage.state = (*stage).init();  // init is a property of a pointer (oh no!)
                         } else {
-                            debug logger.trace ("InitStage {}: starting cleanup", stage.name);
+                            debug logger.trace ("({}) InitStage {}: starting cleanup", threadNum, stage.name);
                             stage.state = stage.cleanup();
                         }
-                        debug logger.trace ("InitStage {}: completed; state: {}", stage.name, stage.state);
+                        debug logger.trace ("({}) InitStage {}: completed; state: {}", threadNum, stage.name, stage.state);
                     } catch (InitStageException e) {
-                        debug logger.trace ("InitStage {}: failed: "~e.msg, stage.name);
+                        debug logger.trace ("({}) InitStage {}: failed: "~e.msg, threadNum, stage.name);
                         stage.state = e.state;
                         doneInit = STATE.ABORT;
                         break threadLoop;
                     } catch (Exception e) {
-                        debug logger.trace ("InitStage {}: failed: "~e.msg, stage.name);
+                        debug logger.trace ("({}) InitStage {}: failed: "~e.msg, threadNum, stage.name);
                         doneInit = STATE.ABORT;
                         break threadLoop;
                     }
@@ -355,19 +363,27 @@
             toRunC.notifyAll(); // Most likely if we're exiting, we should make sure others aren't waiting.
             return;
         }
+        }
         
         // Start min(miscOpts.maxThreads,toRun.size)-1 threads:
         try {
             ThreadGroup g = new ThreadGroup;
-            for (size_t i = numWorking; i > 1; --i)
-                g.create (&initThreadFct);
-            initThreadFct();    // also run in current thread
+            InitStageThread x;
+            for (size_t i = numWorking; i > 1; --i) {
+                //g.create (&initThreadFct);
+                x = new InitStageThread (i);
+                x.start;
+                g.add (x);
+            }
+            x = new InitStageThread (0);
+            x.initThreadFct();    // also run in current thread
             g.joinAll (false);  // don't rethrow exceptions - there SHOULD NOT be any
         } catch (ThreadException e) {
             logger.error ("Exception while using threads: "~e.msg);
             logger.error ("Disabling threads and attempting to continue.");
             miscOpts.set!(int)("NumThreads", 1);        // count includes current thread
-            initThreadFct();                            // try with just this thread
+            auto x = new InitStageThread (0);
+            x.initThreadFct();                            // try with just this thread
         }       // any other exception will be caught in main() and abort program
         
         if (doneInit & STATE.ABORT)