perror( msg ) ;
}
+ pthread_mutex_init( &_MutexPythonWait , NULL ) ;
+ _ExecNumber = 0 ;
+ _GraphExecutingNumber = 0 ;
+ _PyInitModule = false ;
+
// cdebug_out << "FiniteStateMachine::FiniteStateMachine _TransitionTable "
// << endl;
}
pthread_exit( PTHREAD_CANCELED ) ;
}
+int GraphExecutor::FiniteStateMachine::ExecNumber() {
+ PyLock() ;
+ _ExecNumber += 1 ;
+ int RetVal = _ExecNumber ;
+ _GraphExecutingNumber += 1 ;
+ PyUnLock() ;
+ return RetVal ;
+}
+
+void GraphExecutor::FiniteStateMachine::Executed() {
+ PyLock() ;
+ _GraphExecutingNumber -= 1 ;
+ if ( _GraphExecutingNumber == 0 ) {
+ map< string , PyObject * >::iterator aPyFunction ;
+ 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 ;
+ }
+ else {
+ //cout << "GraphExecutor::FiniteStateMachine::Executed " << aPyFunction->first << " erased ..."<< endl ;
+ _MapOfPyFunctions.erase( aPyFunction->first ) ;
+ }
+ }
+ }
+ else {
+ //cout << "GraphExecutor::FiniteStateMachine::Executed _GraphExecutingNumber " << _GraphExecutingNumber
+ // << " != 0 ==> no erase" << endl ;
+ }
+ PyUnLock() ;
+ return ;
+}
+
+bool GraphExecutor::FiniteStateMachine::PyInitModule() {
+ bool InitedModule = _PyInitModule ;
+ _PyInitModule = true ;
+ return InitedModule ;
+}
+
+void GraphExecutor::FiniteStateMachine::PyLock() {
+// cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyLock " << &_MutexPythonWait << endl ;
+ if ( pthread_mutex_lock( &_MutexPythonWait ) ) {
+ perror( "GraphExecutor::FiniteStateMachine::PyLock" ) ;
+ exit( 0 ) ;
+ }
+// cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyLocked " << &_MutexPythonWait << endl ;
+}
+
+void GraphExecutor::FiniteStateMachine::PyUnLock() {
+// cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyUnLock " << &_MutexPythonWait << endl ;
+ if ( pthread_mutex_unlock( &_MutexPythonWait ) ) {
+ perror( "GraphExecutor::FiniteStateMachine::PyUnLock" ) ;
+ exit( 0 ) ;
+ }
+// cout << pthread_self() << " GraphExecutor::FiniteStateMachine::PyUnLocked " << &_MutexPythonWait << endl ;
+}
+
+PyObject * GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncName ) {
+
+ PyObject * RetVal = NULL ;
+ bool PyObjRefIor = !strcmp( aPyFuncName , "PyObjRef" ) || !strcmp( aPyFuncName , "PyObjIor" ) ;
+ PyObject * PyFunctionMapped = _MapOfPyFunctions[ aPyFuncName ] ;
+ if ( _GraphExecutingNumber > 1 && !PyObjRefIor ) {
+ RetVal = PyFunctionMapped ;
+ //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ;
+ if ( RetVal ) {
+ //cout << RetVal << " ob_refcnt " << RetVal->ob_refcnt ;
+ }
+ else {
+ //cout << " NULL" ;
+ }
+ //cout << endl ;
+ }
+ else {
+ RetVal = PyFunctionMapped ;
+ //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) --> " ;
+ if ( RetVal && PyObjRefIor ) {
+ //cout << RetVal << " " << RetVal->ob_refcnt << endl ;
+ }
+ else if ( RetVal ) {
+ //cout << RetVal << " " << RetVal->ob_refcnt << endl ;
+// _MapOfPyFunctions.erase( aPyFuncName ) ;
+// cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' ) erased --> NULL" << endl ;
+ }
+ else {
+ //cout << " NULL" << endl ;
+ }
+ }
+
+ return RetVal ;
+}
+
+bool GraphExecutor::FiniteStateMachine::PyFunction( const char * aPyFuncName , PyObject * aPyFunction ) {
+
+ 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 ;
+ }
+ else {
+ _MapOfPyFunctions[ aPyFuncName ] = aPyFunction ;
+ //cout << "GraphExecutor::FiniteStateMachine::PyFunction( '" << aPyFuncName << "' , " << aPyFunction
+ // << " ) ob_refcnt " << aPyFunction->ob_refcnt << " mapped" << endl ;
+ RetVal = true ;
+ }
+
+ return RetVal ;
+}
+
void GraphExecutor::FiniteStateMachine::JoinThread() {
if ( pthread_mutex_lock( &_MutexJoinWait ) ) {
perror("Join pthread_mutex_lock ") ;