Salome HOME
Gates were not properly handled in Loops ; now they are
authorrahuel <rahuel@opencascade.com>
Fri, 7 Jan 2005 15:15:05 +0000 (15:15 +0000)
committerrahuel <rahuel@opencascade.com>
Fri, 7 Jan 2005 15:15:05 +0000 (15:15 +0000)
Input Values of ports were allowd but were not properly handled : now they are
See GraphInputLoop in examples
See GraphLoopGates and GraphLoopsGates in example

src/GraphExecutor/DataFlowExecutor_InNodeThreads.cxx

index c151d5f4a8dd78a9bf11c0911a6ab55954a27472..42661e2dfda57ac0ed65c790919ea761d19edffc 100644 (file)
@@ -450,17 +450,20 @@ void GraphExecutor::InNode::ThreadStartedAction() {
     exit( 0 ) ;
   }
   if ( !_ThreadStartedSync ) {
-    cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
+    cdebug << pthread_self() << "/" << ThreadNo()
+           << "pthread_cond " << Name() << " ThreadStarted pthread_cond_wait"
            << endl ;
     _ThreadStartedSync = true ;
     if ( pthread_cond_wait( &_ThreadStartedWait , &_MutexWait ) ) {
       perror("ThreadStarted pthread_cond_wait ") ;
     }
-    cdebug << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
+    cdebug << pthread_self() << "/" << ThreadNo()
+           << "pthread_cond " << Name() << " ThreadStarted pthread_cond_waited"
            << endl ;
   }
   else {
-    cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
+    cdebug << pthread_self() << "/" << ThreadNo()
+           << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_wait"
            << endl ;
 //Debug :
     _ThreadStartedSync = false ;  
@@ -468,7 +471,8 @@ void GraphExecutor::InNode::ThreadStartedAction() {
       perror("ThreadStart pthread_cond_signal ") ;
     }
 //Debug
-    cdebug << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
+    cdebug << pthread_self() << "/" << ThreadNo()
+           << "pthread_cond " << Name() << " NO ThreadStarted pthread_cond_signaled"
            << endl ;
   }
   if ( pthread_mutex_unlock( &_MutexWait ) ) {
@@ -483,17 +487,20 @@ void GraphExecutor::InNode::ThreadStartAction() {
     exit( 0 ) ;
   }
   if ( _ThreadStartedSync ) {
-    cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
+    cdebug << pthread_self() << "/" << ThreadNo()
+           << "pthread_cond " << Name() << " ThreadStart pthread_cond_signal"
            << endl ;
     _ThreadStartedSync = false ;  
     if ( pthread_cond_signal( &_ThreadStartedWait ) ) {
       perror("ThreadStart pthread_cond_broadcast ") ;
     }
-    cdebug << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
+    cdebug << pthread_self() << "/" << ThreadNo()
+           << "pthread_cond " << Name() << " ThreadStart pthread_cond_signaled"
            << endl ;
   }
   else {
-    cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
+    cdebug << pthread_self() << "/" << ThreadNo()
+           << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_signal"
            << endl ;
     _ThreadStartedSync = true ;
 //Debug :
@@ -501,7 +508,8 @@ void GraphExecutor::InNode::ThreadStartAction() {
       perror("ThreadStarted pthread_cond_wait ") ;
     }
 //Debug
-    cdebug << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
+    cdebug << pthread_self() << "/" << ThreadNo()
+           << "pthread_cond " << Name() << " NO ThreadStart pthread_cond_waited"
            << endl ;
   }
   if ( pthread_mutex_unlock( &_MutexWait ) ) {
@@ -590,7 +598,7 @@ int GraphExecutor::InNode::executeAction() {
 }
 
 void GraphExecutor::InNode::coutbegin() {
-  cdebug << ThreadNo() << " " << pthread_self() << " run_function begin"
+  cdebug << pthread_self() << "/" << ThreadNo() << " run_function begin"
          << " " << Name() << " " << Automaton()->StateName( State() ) << endl ;
 }
 void GraphExecutor::InNode::coutexit() {
@@ -627,12 +635,12 @@ void * run_function(void *p) {
 int GraphExecutor::InNode::ExecuteAction() {
   int sts ;
 
-//  const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
-//  const char * statename = Automaton()->StateName( State() ) ;
-//  const char * nextstatename = Automaton()->StateName( _NextState ) ;
-//  cdebug << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
-//         << nextactionname << " "  << statename << " NextState "
-//         << nextstatename << endl ;
+  const char * nextactionname = Automaton()->ActionName( _NextAction ) ;
+  const char * statename = Automaton()->StateName( State() ) ;
+  const char * nextstatename = Automaton()->StateName( _NextState ) ;
+  cdebug_in << pthread_self() << "/" << ThreadNo() << " --> ExecuteAction "
+            << nextactionname << " "  << statename << " NextState "
+            << nextstatename << endl ;
 
   State( _NextState ) ;
   switch ( _NextAction ) {
@@ -763,8 +771,8 @@ int GraphExecutor::InNode::ExecuteAction() {
     return 0 ;
   }
   }
-//  cdebug << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
-//         << Automaton()->ActionName( nextaction ) << endl ;
+  cdebug_out << pthread_self() << "/" << ThreadNo() << "<-- ExecuteAction "
+             << nextactionname << endl ;
   return sts ;
 }
 
@@ -1792,16 +1800,21 @@ void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
   State( GraphExecutor::DataWaitingState ) ;
   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
-    if ( anInPort->IsGate() ) { // Loop : Open the doors
+    cdebug << "SetWaitingStates InPort " << Name() << "( " << anInPort->PortName() << " ) "
+           << anInPort->PortStatus() << " " << anInPort->State() << endl ;
+// JR Debug 07.01.2005 : Close the Gates instead of open !!!
+    if ( anInPort->IsGate() ) { // Loop : Close the doors
       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
       if ( anOutPort ) {
         CORBA::Any * anAny = new CORBA::Any() ;
-        *anAny <<= (long ) 1 ;
+//        *anAny <<= (long ) 1 ;
+        *anAny <<= (long ) 0 ;
         anOutPort->Value( anAny ) ;
-        anInPort->State( SUPERV::ReadyState ) ;
+        anInPort->State( SUPERV::WaitingState ) ;
       }
     }
-    else if ( anInPort->State() != SUPERV::WaitingState ) {
+    else if ( anInPort->State() != SUPERV::WaitingState &&
+              !anInPort->IsDataConnected() ) {
       if ( !docdebug ) {
         cdebug << ThreadNo()
                << " --> GraphExecutor::InNodeThreads::SetWaitingStates " << Name() << endl;
@@ -1811,13 +1824,14 @@ void GraphExecutor::InNode::SetWaitingStates(GraphExecutor::InNode * EndNode ) {
         anInPort->State( SUPERV::WaitingState ) ;
       }
     }
+    cdebug << "               --> " << Name() << "( " << anInPort->PortName() << " ) "
+           << anInPort->PortStatus() << " " << anInPort->State() << endl ;
   }
   for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
     GraphBase::OutPort * anOutPort = GetChangeNodeOutPort( i ) ;
     for ( j = 0 ; j < anOutPort->InPortsSize() ; j++ ) {
       if ( !( IsGOTONode() && anOutPort->IsGate() ) &&
-           !( IsEndLoopNode() && ( anOutPort->IsGate() ||
-              anOutPort->IsLoop() ) ) &&
+           !( IsEndLoopNode() && ( anOutPort->IsGate() || anOutPort->IsLoop() ) ) &&
            !anOutPort->IsDataStream() &&
            !anOutPort->ChangeInPorts( j )->IsDataStream() &&
            !anOutPort->ChangeInPorts( j )->IsExternConnected() ) {
@@ -1888,6 +1902,14 @@ int GraphExecutor::InNode::Successed_SuccessAction() {
       cdebug << ThreadNo() << " Successed_SuccessAction " << Name() << " will Loop to HeadNode "
              << aLabelNode->Name() << " from port " << anInPort->PortName() << endl ;
       aLabelNode->SetWaitingStates( this ) ;
+// JR 07.01.2005 Debug : Open the Gate of the coupledNode closed by SetWaitingStates
+      GraphBase::OutPort * anOutPort = aLabelNode->GetChangeNodeInGate()->GetOutPort() ;
+      if ( anOutPort ) {
+        CORBA::Any * anAny = new CORBA::Any() ;
+        *anAny <<= (long ) 1 ;
+        anOutPort->Value( anAny ) ;
+        aLabelNode->GetChangeNodeInGate()->State( SUPERV::ReadyState ) ;
+      }
       for ( j = 0 ; j < aLabelNode->GetNodeInPortsSize() ; j++ ) {
         const GraphBase::InPort * anInPort = aLabelNode->GetNodeInPort( j ) ;
         if ( anInPort->GetOutPort() ) {
@@ -2392,7 +2414,8 @@ void GraphExecutor::InNode::InParametersSet( bool & Err ,
         *anAny <<= (long ) 0 ;
         theOutPort->Value( anAny ) ;
       }
-      if ( !anInPort->IsDataStream() ) {
+      if ( !anInPort->IsDataStream() &&
+           !anInPort->IsDataConnected() ) {
         anInPort->State( SUPERV::WaitingState ) ;
       }
       D.Name = CORBA::string_dup( anInPort->GetServicesParameter().Parametername ) ;