From 051b5c07429c9ed544fce69c3c03644bd71621aa Mon Sep 17 00:00:00 2001 From: prascle Date: Mon, 4 Sep 2006 05:27:15 +0000 Subject: [PATCH] PR: from Sergey Mozokhin, Supervisor problem, crash after killing a dataflow execution. --- src/Container/Component_i.cxx | 32 +++++++++++++++++++++++----- src/Container/Container_i.cxx | 10 +++++++++ src/Container/SALOME_Component_i.hxx | 2 ++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 0e6a5c0ab..934019a98 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -95,7 +95,8 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _Executed(false) , _graphName("") , _nodeName(""), - _studyId(-1) + _studyId(-1), + _CanceledThread(false) { MESSAGE("Component constructor with instanceName "<< _instanceName); //SCRUTE(pd_refCount); @@ -140,7 +141,8 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, _Executed(false) , _graphName("") , _nodeName(""), - _studyId(-1) + _studyId(-1), + _CanceledThread(false) { _orb = CORBA::ORB::_duplicate(orb); _poa = PortableServer::POA::_duplicate(poa); @@ -333,7 +335,7 @@ bool Engines_Component_i::Kill_impl() #ifndef WNT if ( _ThreadId > 0 && pthread_self() != _ThreadId ) { - RetVal = Killer( _ThreadId , 0 ) ; + RetVal = Killer( _ThreadId , SIGUSR2 ) ; _ThreadId = (pthread_t ) -1 ; } @@ -581,6 +583,7 @@ void Engines_Component_i::beginService(const char *serviceName) _ThreadCpuUsed = 0 ; _Executed = true ; _serviceName = serviceName ; + theEngines_Component = this ; if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) { perror("pthread_setcanceltype ") ; @@ -632,7 +635,8 @@ void Engines_Component_i::beginService(const char *serviceName) void Engines_Component_i::endService(const char *serviceName) { - _ThreadCpuUsed = CpuUsed_impl() ; + if ( !_CanceledThread ) + _ThreadCpuUsed = CpuUsed_impl() ; MESSAGE(pthread_self() << " Send EndService notification for " << serviceName << endl << " Component instance : " << _instanceName << " StartUsed " << _StartUsed << " _ThreadCpuUsed "<< _ThreadCpuUsed << endl <SetCurCpu() ; + if ( theEngines_Component ) + theEngines_Component->SetCurCpu() ; } //============================================================================= @@ -766,6 +771,23 @@ long Engines_Component_i::CpuUsed() return cpu ; } +void CallCancelThread() +{ + if ( theEngines_Component ) + theEngines_Component->CancelThread() ; +} + +//============================================================================= +/*! + * C++ method: + */ +//============================================================================= + +void Engines_Component_i::CancelThread() +{ + _CanceledThread = true; +} + //============================================================================= /*! * C++ method: Send message to event channel diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index acdbe7f63..9b2174d46 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -905,6 +905,11 @@ void ActSigIntHandler() perror("SALOME_Container main ") ; exit(0) ; } + if ( sigaction( SIGUSR2 , &SigIntAct, NULL ) ) + { + perror("SALOME_Container main ") ; + exit(0) ; + } //PAL9042 JR : during the execution of a Signal Handler (and of methods called through Signal Handlers) // use of streams (and so on) should never be used because : @@ -922,6 +927,7 @@ void ActSigIntHandler() } void SetCpuUsed() ; +void CallCancelThread() ; #ifndef WNT void SigIntHandler(int what , @@ -952,6 +958,10 @@ void SigIntHandler(int what , { SetCpuUsed() ; } + else if ( siginfo->si_signo == SIGUSR2 ) + { + CallCancelThread() ; + } else { _Sleeping = true ; diff --git a/src/Container/SALOME_Component_i.hxx b/src/Container/SALOME_Component_i.hxx index 3d988b4a4..6b4261d78 100644 --- a/src/Container/SALOME_Component_i.hxx +++ b/src/Container/SALOME_Component_i.hxx @@ -126,6 +126,7 @@ public: bool Killer( pthread_t ThreadId , int signum ); void SetCurCpu() ; long CpuUsed() ; + void CancelThread() ; protected: int _studyId; // -1: not initialised; 0: multiStudy; >0: study @@ -157,6 +158,7 @@ private: long _StartUsed ; long _ThreadCpuUsed ; bool _Executed ; + bool _CanceledThread ; }; #endif -- 2.39.2