X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGraphExecutor%2FDataFlowExecutor_FiniteStateMachine.cxx;h=f43eb79f471679a6b37b18e9939950a66dcb90a4;hb=dad24b20fb0b0c18474caa7cb5b94652408b6743;hp=9916c77c7912edf75b2e8752ab0c9ec9d1a0cda9;hpb=e92234e01975ce15be247ff9d03f7b3e9cd7fccb;p=modules%2Fsuperv.git diff --git a/src/GraphExecutor/DataFlowExecutor_FiniteStateMachine.cxx b/src/GraphExecutor/DataFlowExecutor_FiniteStateMachine.cxx index 9916c77..f43eb79 100644 --- a/src/GraphExecutor/DataFlowExecutor_FiniteStateMachine.cxx +++ b/src/GraphExecutor/DataFlowExecutor_FiniteStateMachine.cxx @@ -78,8 +78,8 @@ void * start_function( void *p ) ; #define SuspendedState GraphExecutor::SuspendedState #define KilledState GraphExecutor::KilledState #define StoppedState GraphExecutor::StoppedState -#define ReRunnedState GraphExecutor::ReRunnedState #define ReStartedState GraphExecutor::ReStartedState +#define LoadingState GraphExecutor::LoadingState #define NumberOfAutomatonStates GraphExecutor::NumberOfAutomatonStates #endif @@ -125,7 +125,7 @@ void * start_function( void *p ) ; #define NumberOfEvents GraphExecutor::NumberOfEvents GraphExecutor::FiniteStateMachine::FiniteStateMachine() { -// cdebug_in << "FiniteStateMachine::FiniteStateMachine" << endl; + MESSAGE( "FiniteStateMachine::FiniteStateMachine" ) ; _ControlStateName[ VoidState ] = "VoidState" ; _ControlStateName[ ToSuspendStartState ]= "ToSuspendStartState" ; @@ -166,8 +166,8 @@ GraphExecutor::FiniteStateMachine::FiniteStateMachine() { _StateName[ SuspendedState ] = "SuspendedState" ; _StateName[ KilledState ] = "KilledState" ; _StateName[ StoppedState ] = "StoppedState" ; - _StateName[ ReRunnedState ] = "ReRunnedState" ; _StateName[ ReStartedState ] = "ReStartedState" ; + _StateName[ LoadingState ] = "LoadingState" ; _EventName[ UndefinedEvent ] = "UndefinedEvent" ; _EventName[ NewThreadEvent ] = "NewThreadEvent" ; @@ -229,7 +229,8 @@ GraphExecutor::FiniteStateMachine::FiniteStateMachine() { _ActionName[ Executing_StopAction ] = "Executing_StopAction" ; _ActionName[ Executing_SuccessAction ] = "Executing_SuccessAction" ; - _ActionName[ Executing_ErrorAction ] = "Executing_ErrorAction" ; +// _ActionName[ Executing_ErrorAction ] = "Executing_ErrorAction" ; + _ActionName[ Errored_ExecutingAction ] = "Errored_ExecutingAction" ; _ActionName[ Successed_SuccessAction ] = "Successed_SuccessAction" ; _ActionName[ Errored_ErrorAction ] = "Errored_ErrorAction" ; @@ -261,8 +262,6 @@ GraphExecutor::FiniteStateMachine::FiniteStateMachine() { _GraphStateName[ SUPERV::SuspendErroredState ] = "SuspendErroredState" ; _GraphStateName[ SUPERV::KillState ] = "KillState" ; _GraphStateName[ SUPERV::StopState ] = "StopState" ; - _GraphStateName[ SUPERV::ReRunState ] = "ReRunState" ; - _GraphStateName[ SUPERV::ReStartState ] = "ReStartState" ; int i , j ; // NewStates = _TransitionTable[ States ] [ Events ] @@ -357,12 +356,19 @@ GraphExecutor::FiniteStateMachine::FiniteStateMachine() { // SuspendedExecutingState : NO ResumeEvent 13-03-2003 _TransitionTable[ SuspendedExecutingState ][ SuccessEvent ] = SuccessedExecutingState ; _ActionTable[ SuccessedExecutingState ][ SuccessEvent ] = Executing_SuccessAction; +//JR 24.03.2005 : Debug for PAL8176 : abort of GOTONode +// ErrorEvent + _TransitionTable[ SuccessedState ][ ErrorEvent ] = ErroredExecutingState ; +// _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction; + _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Errored_ExecutingAction; // ErrorEvent _TransitionTable[ ExecutingState ][ ErrorEvent ] = ErroredExecutingState ; - _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction; +// _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction; + _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Errored_ExecutingAction; // SuspendedExecutingState : NO ResumeEvent 13-03-2003 _TransitionTable[ SuspendedExecutingState ][ ErrorEvent ] = ErroredExecutingState ; - _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction; +// _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Executing_ErrorAction; + _ActionTable[ ErroredExecutingState ][ ErrorEvent ] = Errored_ExecutingAction; // DONE-CONTROL : // SuccessedExecutingState - SuccessEvent @@ -455,13 +461,17 @@ GraphExecutor::FiniteStateMachine::FiniteStateMachine() { perror( msg ) ; } +#if omniORB_4_0_5 + _SuperVisionComponent = SUPERV::SuperG::_nil() ; +#endif + pthread_mutex_init( &_MutexPythonWait , NULL ) ; + _MutexPythonLocked = false ; _ExecNumber = 0 ; _GraphExecutingNumber = 0 ; _PyInitModule = false ; _DbgFileNumber = 0 ; -// cdebug_out << "FiniteStateMachine::FiniteStateMachine _TransitionTable " -// << endl; + MESSAGE( "FiniteStateMachine::FiniteStateMachine _TransitionTable " ) ; } void * start_function( void *p ) { @@ -495,22 +505,28 @@ void GraphExecutor::FiniteStateMachine::Executed() { for ( aPyFunction = _MapOfPyFunctions.begin() ; aPyFunction != _MapOfPyFunctions.end() ; aPyFunction++ ) { if ( !strcmp( aPyFunction->first.c_str() , "PyObjRef" ) || !strcmp( aPyFunction->first.c_str() , "PyObjIor" ) ) { - //cout << "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " keeped ..."<< endl ; + MESSAGE( "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " keeped ..." + ) ; } else { - //cout << "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " erased ..."<< endl ; + MESSAGE( "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " erased ..." + ) ; _MapOfPyFunctions.erase( aPyFunction->first ) ; } } } else { - //cout << "GraphExecutor::FiniteStateMachine::Executed _GraphExecutingNumber " << _GraphExecutingNumber - // << " != 0 ==> no erase" << endl ; + MESSAGE( "GraphExecutor::FiniteStateMachine::Executed _GraphExecutingNumber " + << _GraphExecutingNumber << " != 0 ==> no erase" ) ; } PyUnLock() ; return ; } +void GraphExecutor::FiniteStateMachine::PyInitModule( bool aPyInitModule ) { + _PyInitModule = aPyInitModule ; +} + bool GraphExecutor::FiniteStateMachine::PyInitModule() { bool InitedModule = _PyInitModule ; _PyInitModule = true ; @@ -523,6 +539,7 @@ void GraphExecutor::FiniteStateMachine::PyLock() { perror( "GraphExecutor::FiniteStateMachine::PyLock" ) ; exit( 0 ) ; } + _MutexPythonLocked = true ; // cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyLocked " << &_MutexPythonWait << endl ; } @@ -532,9 +549,17 @@ void GraphExecutor::FiniteStateMachine::PyUnLock() { perror( "GraphExecutor::FiniteStateMachine::PyUnLock" ) ; exit( 0 ) ; } + _MutexPythonLocked = false ; // cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyUnLocked " << &_MutexPythonWait << endl ; } +void GraphExecutor::FiniteStateMachine::PyLockReset() { + if ( _MutexPythonLocked ) { + PyUnLock() ; + } +} + +#define PyFunctionTrace 1 PyObject * GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncName ) { PyObject * RetVal = NULL ; @@ -542,29 +567,30 @@ PyObject * GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncNa PyObject * PyFunctionMapped = _MapOfPyFunctions[ aPyFuncName ] ; if ( _GraphExecutingNumber > 1 && !PyObjRefIor ) { RetVal = PyFunctionMapped ; - //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ; +#if PyFunctionTrace + MESSAGE( "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ) ; if ( RetVal ) { - //cout << RetVal << " ob_refcnt " << RetVal->ob_refcnt ; + MESSAGE( RetVal << " ob_refcnt " << RetVal->ob_refcnt ) ; } else { - //cout << " NULL" ; + MESSAGE( " NULL" ) ; } - //cout << endl ; +#endif } else { RetVal = PyFunctionMapped ; - //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ; +#if PyFunctionTrace + MESSAGE( "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ) ; if ( RetVal && PyObjRefIor ) { - //cout << RetVal << " " << RetVal->ob_refcnt << endl ; + MESSAGE( RetVal << " " << RetVal->ob_refcnt ) ; } else if ( RetVal ) { - //cout << RetVal << " " << RetVal->ob_refcnt << endl ; -// _MapOfPyFunctions.erase( aPyFuncName ) ; -// cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) erased --> NULL" << endl ; + MESSAGE( RetVal << " " << RetVal->ob_refcnt ) ; } else { - //cout << " NULL" << endl ; + MESSAGE( " NULL" ) ; } +#endif } return RetVal ; @@ -574,21 +600,38 @@ bool GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncName , P bool RetVal = false ; if ( _MapOfPyFunctions[ aPyFuncName ] != NULL ) { - //PyObject * aPyFunc = _MapOfPyFunctions[ aPyFuncName ] ; - //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' , " << aPyFunction - // << " ) ob_refcnt " << aPyFunction->ob_refcnt << " already mapped : " << aPyFunc << " ob_refcnt " - // << aPyFunc->ob_refcnt << endl ; +#if PyFunctionTrace + PyObject * aPyFunc = _MapOfPyFunctions[ aPyFuncName ] ; + MESSAGE( "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' , aPyFunction " + << aPyFunction << " ) ob_refcnt " << aPyFunction->ob_refcnt << " already mapped : " + << aPyFunc << " ob_refcnt " << aPyFunc->ob_refcnt ) ; +#endif } else { _MapOfPyFunctions[ aPyFuncName ] = aPyFunction ; - //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' , " << aPyFunction - // << " ) ob_refcnt " << aPyFunction->ob_refcnt << " mapped" << endl ; +#if PyFunctionTrace + MESSAGE( "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) " << aPyFunction + << " ) ob_refcnt " << aPyFunction->ob_refcnt << " mapped" ) ; +#endif RetVal = true ; } return RetVal ; } +bool GraphExecutor::FiniteStateMachine::ErasePyFunction( const char * aPyFuncName ) { + +#if PyFunctionTrace + MESSAGE( "GraphExecutor::FiniteStateMachine::ErasePyFunction( '" << aPyFuncName << "' )" ) ; +#endif + if ( _MapOfPyFunctions[ aPyFuncName ] != NULL ) { + _MapOfPyFunctions.erase( aPyFuncName ) ; + return true ; + } + return false ; +} + +/* GraphBase::Graph * GraphExecutor::FiniteStateMachine::MapGraph( const char * aGraphName ) { GraphBase::Graph * aGraph = _MapOfGraphs[ aGraphName ] ; //cout << "MapGraph " << aGraphName << " --> " << aGraph << endl ; @@ -632,32 +675,37 @@ string GraphExecutor::FiniteStateMachine::GraphInstanceName( const char * aGraph // << theGraphInstanceName << endl ; return theGraphInstanceName ; } +*/ void GraphExecutor::FiniteStateMachine::JoinThread() { if ( pthread_mutex_lock( &_MutexJoinWait ) ) { - perror("Join pthread_mutex_lock ") ; + perror("FiniteStateMachine:JoinThread pthread_mutex_lock ") ; exit( 0 ) ; } while ( _JoinThread ) { while ( _ThreadList.size() == 0) { -// MESSAGE( pthread_self() << " Join pthread_cond_wait" ); +// MESSAGE( pthread_self() << " FiniteStateMachine:Join pthread_cond_wait" ); if ( pthread_cond_wait( &_JoinWait , &_MutexJoinWait ) ) { - perror("Join pthread_cond_wait ") ; + perror("FiniteStateMachine:JoinThread pthread_cond_wait ") ; } } pthread_t _Thread = _ThreadList.front() ; -// MESSAGE( pthread_self() << " Join pthread_cond_waited : " << _Thread ) - _ThreadList.pop_front() ; -// MESSAGE( pthread_self() << " Join pthread_join : " << _Thread ); +// MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_cond_waited : " << _Thread ) +// MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_join : " << _Thread ); int joinsts = pthread_join( _Thread , NULL ) ; -// MESSAGE( pthread_self() << " Join pthread_joined : " << _Thread ); if ( joinsts ) { - perror("Join pthread_join ") ; -// exit( 0 ) ; + perror("FiniteStateMachine:JoinThread pthread_join ") ; + MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_join : " << _Thread + << " Error" ); + exit( 0 ) ; + } + else { +// MESSAGE( pthread_self() << " FiniteStateMachine:JoinThread pthread_joined : " << _Thread ); + _ThreadList.pop_front() ; } } if ( pthread_mutex_unlock( &_MutexJoinWait ) ) { - perror("Join pthread_mutex_unlock ") ; + perror("FiniteStateMachine:JoinThread pthread_mutex_unlock ") ; exit( 0 ) ; } } @@ -775,12 +823,12 @@ ostream & operator<< (ostream &f ,const GraphExecutor::AutomatonState & aState ) case GraphExecutor::SuspendedErroredToReStartState : f << "SuspendedErroredToReStartState"; break; - case GraphExecutor::ReRunnedState : - f << "ReRunnedState"; - break; case GraphExecutor::ReStartedState : f << "ReStartedState"; break; + case GraphExecutor::LoadingState : + f << "LoadingState"; + break; default : f << "GraphExecutor::AutomatonState_?"; break;