]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.cxx
CMake 2.6 compatibility
[bbtk.git] / kernel / src / bbtkBlackBox.cxx
index 859430f349098c23951b9cd75b3d9e4c245ad42f..3b3955622d59b996fb88bcd0989b5b2923b99b4b 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/11/12 15:42:52 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2008/11/13 14:46:43 $
+  Version:   $Revision: 1.28 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -103,6 +103,7 @@ namespace bbtk
   BlackBox::BlackBox(const std::string &name) 
     : 
     bbmStatus(MODIFIED), 
+    bbmExecuting(false),
     bbmName(name),
     bbmBoxProcessMode("Pipeline"),
     bbmParent()
@@ -123,6 +124,7 @@ namespace bbtk
   BlackBox::BlackBox(BlackBox& from, const std::string &name) 
     :
       bbmStatus(from.bbmStatus), 
+      bbmExecuting(false),
       bbmName(name), 
       bbmBoxProcessMode(from.bbmBoxProcessMode),
       bbmParent()
@@ -155,9 +157,16 @@ namespace bbtk
   void BlackBox::bbExecute(bool force)
   {
     bbtkDebugMessageInc("process",2,
-                       "=> BlackBox::bbExecute() ["
+                       "=> BlackBox::bbExecute("<<(int)force<<") ["
                        <<bbGetFullName()<<"]"<<std::endl);
  
+    // If already executing : return
+    if (bbGetExecuting()) 
+      {
+       bbtkDebugMessage("process",2,
+                        " -> already executing : bailing out"<<std::endl);
+       return;
+      }
 
     // If execution frozen : return
     if (bbGlobalGetFreezeExecution()) 
@@ -1127,32 +1136,38 @@ namespace bbtk
    }
   //=========================================================================
 
+  static bool bbmgGlobalProcessingExecutionList = false;
 
   //=========================================================================
    void BlackBox::bbGlobalProcessExecutionList()
    {   
      bbtkDebugMessageInc("process",3,
                         "=> BlackBox::bbGlobalProcessExecutionList()"
-                        <<std::endl);     
-     
-     std::set<BlackBox::WeakPointer>::iterator i;
-     for (i=bbmgExecutionList.begin();
-         i!=bbmgExecutionList.end();
-         ++i)
+                        <<std::endl);    
+     if (bbmgGlobalProcessingExecutionList) 
        {
-        {
-          if ((*i).lock())
-            {
-              bbtkDebugMessage("process",4,
-                               " -> Executing "<<
-                               (*i).lock()->bbGetFullName()<<std::endl);
-              (*i).lock()->bbExecute(true);
-            }
-          else 
-            {
-              bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid...");
-            }
-        }
+        bbtkDebugMessage("process",3,"BlackBox::bbGlobalProcessExecutionList() reentered !");
+        return;
+       }
+     bbmgGlobalProcessingExecutionList = true;
+
+     std::set<BlackBox::WeakPointer>::iterator i; 
+     while (bbmgExecutionList.size()>0)
+       {
+        i = bbmgExecutionList.begin();
+        BlackBox::WeakPointer p = *i;
+        bbmgExecutionList.erase(i);
+        if (p.lock())
+          {
+            bbtkDebugMessage("process",4,
+                             " -> Executing "<<
+                             p.lock()->bbGetFullName()<<std::endl);
+            p.lock()->bbExecute(true);
+          }
+        else 
+          {
+            bbtkGlobalError("Strange error in BlackBox::bbGlobalProcessExecutionList() : Weak bb pointer in bbmgExecutionList is no more valid...");
+          }
        }
      
      bbmgExecutionList.clear();
@@ -1160,6 +1175,7 @@ namespace bbtk
                         "<= BlackBox::bbGlobalProcessExecutionList()"
                         <<std::endl);     
      
+     bbmgGlobalProcessingExecutionList = false;
      
    }
   //=========================================================================
@@ -1185,9 +1201,14 @@ namespace bbtk
        }
 
   void BlackBox::bbGlobalAddToExecutionList( BlackBox::Pointer b )
-       {  
-               bbmgExecutionList.insert(b); 
-       } 
+  {  
+    bbtkDebugMessage("process",3,"* bbGlobalAddToExecutionList("<<b->bbGetFullName()<<")"<<std::endl);
+    if (bbmgGlobalProcessingExecutionList) 
+      {
+       bbtkDebugMessage("process",3,"bbGlobalAddToExecutionList called inside bbGlobalProcessExecutionList !");
+      }
+    bbmgExecutionList.insert(b); 
+  } 
 
 
    //=========================================================================