Commit 921bf412 authored by Pavel Vainerman's avatar Pavel Vainerman

(UniSetActivator): небольшая правка механизма завершения

parent b596a688
...@@ -66,7 +66,6 @@ namespace uniset ...@@ -66,7 +66,6 @@ namespace uniset
public: public:
static UniSetActivatorPtr Instance(); static UniSetActivatorPtr Instance();
void Destroy();
std::shared_ptr<UniSetActivator> get_aptr(); std::shared_ptr<UniSetActivator> get_aptr();
// ------------------------------------ // ------------------------------------
...@@ -84,15 +83,8 @@ namespace uniset ...@@ -84,15 +83,8 @@ namespace uniset
typedef sigc::signal<void, int> TerminateEvent_Signal; typedef sigc::signal<void, int> TerminateEvent_Signal;
TerminateEvent_Signal signal_terminate_event(); TerminateEvent_Signal signal_terminate_event();
inline bool noUseGdbForStackTrace() const bool noUseGdbForStackTrace() const;
{ const std::string getAbortScript() const;
return _noUseGdbForStackTrace;
}
inline const std::string getAbortScript()
{
return abortScript;
}
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
// Поддрежка REST API (IHttpRequestRegistry) // Поддрежка REST API (IHttpRequestRegistry)
......
...@@ -296,15 +296,32 @@ static void on_stacktrace_timeout() ...@@ -296,15 +296,32 @@ static void on_stacktrace_timeout()
ulogsys << "****** STACK TRACE guard thread finish ******" << endl << flush; ulogsys << "****** STACK TRACE guard thread finish ******" << endl << flush;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
static void start_terminate_process()
{
// посылаем сигнал потоку завершения, чтобы проснулся и начал заверешение
{
std::unique_lock<std::mutex> lk(g_termmutex);
if( g_term )
return;
g_term = true;
}
g_termevent.notify_all();
}
// ------------------------------------------------------------------------------------------
static void wait_done()
{
std::unique_lock<std::mutex> lk(g_donemutex);
while( !g_done )
g_doneevent.wait(lk, []() { return (g_done == true); } );
}
// ------------------------------------------------------------------------------------------
static void activator_terminate( int signo ) static void activator_terminate( int signo )
{ {
if( g_term ) if( g_term )
return; return;
ulogsys << "****** TERMINATE SIGNAL=" << signo << endl << flush; g_signo = signo;
g_term = true;
if( signo == SIGABRT ) if( signo == SIGABRT )
{ {
if( g_act && !g_act->noUseGdbForStackTrace() ) if( g_act && !g_act->noUseGdbForStackTrace() )
...@@ -314,11 +331,14 @@ static void activator_terminate( int signo ) ...@@ -314,11 +331,14 @@ static void activator_terminate( int signo )
} }
else else
printStackTrace(); printStackTrace();
// exit(EXIT_FAILURE);
// return;
} }
// else
// exit(EXIT_SUCCESS);
ulogsys << "****** TERMINATE NOTIFY...(signo=" << signo << ")" << endl << flush; start_terminate_process();
g_signo = signo;
g_termevent.notify_one();
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
static void activator_terminate_with_calltrace( int signo ) static void activator_terminate_with_calltrace( int signo )
...@@ -338,7 +358,7 @@ static void activator_terminate_with_calltrace( int signo ) ...@@ -338,7 +358,7 @@ static void activator_terminate_with_calltrace( int signo )
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void finished_thread() void finished_thread()
{ {
ulogsys << "****** FINISHED START **** " << endl << flush; ulogsys << "****** WAIT FINISH START **** " << endl << flush;
std::unique_lock<std::mutex> lk(g_finimutex); std::unique_lock<std::mutex> lk(g_finimutex);
if( g_finished ) if( g_finished )
...@@ -351,7 +371,7 @@ void finished_thread() ...@@ -351,7 +371,7 @@ void finished_thread()
{ {
return (g_work_stopped == true); return (g_work_stopped == true);
} ); } );
ulogsys << "****** FINISHED END ****" << endl << flush; ulogsys << "****** WAIT FINISH END(" << g_work_stopped << ") ****" << endl << flush;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void on_finish_timeout() void on_finish_timeout()
...@@ -368,11 +388,11 @@ void on_finish_timeout() ...@@ -368,11 +388,11 @@ void on_finish_timeout()
if( !g_done ) if( !g_done )
{ {
ulogsys << "****** KILL TIMEOUT.. *******" << endl << flush; ulogsys << "(KILL THREAD): WAIT TIMEOUT..KILL *******" << endl << flush;
raise(SIGKILL); raise(SIGKILL);
} }
ulogsys << "KILL THREAD: ..bye.." << endl; ulogsys << "(KILL THREAD): ..bye.." << endl;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
namespace uniset namespace uniset
...@@ -475,7 +495,7 @@ namespace uniset ...@@ -475,7 +495,7 @@ namespace uniset
} }
} }
g_act.reset(); g_act = nullptr;
UniSetActivator::set_signals(false); UniSetActivator::set_signals(false);
} }
...@@ -505,11 +525,6 @@ UniSetActivatorPtr UniSetActivator::Instance() ...@@ -505,11 +525,6 @@ UniSetActivatorPtr UniSetActivator::Instance()
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
void UniSetActivator::Destroy()
{
inst.reset();
}
// ---------------------------------------------------------------------------
std::shared_ptr<UniSetActivator> UniSetActivator::get_aptr() std::shared_ptr<UniSetActivator> UniSetActivator::get_aptr()
{ {
return std::dynamic_pointer_cast<UniSetActivator>(get_ptr()); return std::dynamic_pointer_cast<UniSetActivator>(get_ptr());
...@@ -565,35 +580,12 @@ void UniSetActivator::init() ...@@ -565,35 +580,12 @@ void UniSetActivator::init()
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
UniSetActivator::~UniSetActivator() UniSetActivator::~UniSetActivator()
{ {
if( !g_term && orbthr )
{
{
std::unique_lock<std::mutex> locker(g_termmutex);
g_term = true;
}
g_signo = 0;
g_termevent.notify_one();
ulogsys << myname << "(~UniSetActivator): wait done.." << endl;
#if 1
// if( g_term_thread->joinable() )
// g_term_thread->join();
#else
std::unique_lock<std::mutex> locker(g_donemutex);
while( !g_done )
g_doneevent.wait(locker);
#endif
ulogsys << myname << "(~UniSetActivator): wait done OK." << endl;
}
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::uaDestroy(int signo) void UniSetActivator::uaDestroy( int signo )
{ {
if( omDestroy || !g_act ) if( omDestroy || !g_act )
return; return;
...@@ -783,13 +775,7 @@ void UniSetActivator::work() ...@@ -783,13 +775,7 @@ void UniSetActivator::work()
g_finievent.notify_one(); g_finievent.notify_one();
if( orbthr ) if( orbthr )
{ wait_done();
// HACK: почему-то мы должны тут застрять,
// иначе "где-то" возникает "гонка" с потоком завершения
// и мы получаем SIGABRT уже на самом завершении
// (помоему как-то связано с завершением потоков)
msleep(THREAD_TERMINATE_PAUSE); // pause();
}
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
CORBA::ORB_ptr UniSetActivator::getORB() CORBA::ORB_ptr UniSetActivator::getORB()
...@@ -882,6 +868,16 @@ UniSetActivator::TerminateEvent_Signal UniSetActivator::signal_terminate_event() ...@@ -882,6 +868,16 @@ UniSetActivator::TerminateEvent_Signal UniSetActivator::signal_terminate_event()
return s_term; return s_term;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool UniSetActivator::noUseGdbForStackTrace() const
{
return _noUseGdbForStackTrace;
}
// ------------------------------------------------------------------------------------------
const string UniSetActivator::getAbortScript() const
{
return abortScript;
}
// ------------------------------------------------------------------------------------------
#ifndef DISABLE_REST_API #ifndef DISABLE_REST_API
Poco::JSON::Object::Ptr UniSetActivator::httpGetByName( const string& name, const Poco::URI::QueryParameters& p ) Poco::JSON::Object::Ptr UniSetActivator::httpGetByName( const string& name, const Poco::URI::QueryParameters& p )
{ {
...@@ -986,21 +982,10 @@ void UniSetActivator::normalexit() ...@@ -986,21 +982,10 @@ void UniSetActivator::normalexit()
if( !g_act ) if( !g_act )
return; return;
ulogsys << g_act->getName() << "(default exit): ..begin..." << endl << flush; ulogsys << g_act->getName() << "(exit): ..begin..." << endl << flush;
start_terminate_process();
if( !g_term )
{
// прежде чем вызывать notify_one(), мы должны освободить mutex!
{
std::unique_lock<std::mutex> locker(g_termmutex);
g_term = true;
g_signo = 0;
}
ulogsys << "(default exit): notify terminate.." << endl << flush;
g_termevent.notify_one();
}
ulogsys << "(default exit): wait done.." << endl << flush; ulogsys << "(exit): wait done.." << endl << flush;
#if 1 #if 1
if( g_term_thread && g_term_thread->joinable() ) if( g_term_thread && g_term_thread->joinable() )
...@@ -1018,7 +1003,7 @@ void UniSetActivator::normalexit() ...@@ -1018,7 +1003,7 @@ void UniSetActivator::normalexit()
#endif #endif
ulogsys << "(default exit): wait done OK (good bye)" << endl << flush; ulogsys << "(exit): wait done OK (good bye)" << endl << flush;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::normalterminate() void UniSetActivator::normalterminate()
...@@ -1027,37 +1012,7 @@ void UniSetActivator::normalterminate() ...@@ -1027,37 +1012,7 @@ void UniSetActivator::normalterminate()
return; return;
ulogsys << g_act->getName() << "(default terminate): ..begin..." << endl << flush; ulogsys << g_act->getName() << "(default terminate): ..begin..." << endl << flush;
normalexit();
if( !g_term )
{
// прежде чем вызывать notify_one(), мы должны освободить mutex!
{
std::unique_lock<std::mutex> locker(g_termmutex);
g_term = true;
g_signo = 0;
}
ulogsys << "(default terminate): notify terminate.." << endl << flush;
g_termevent.notify_one();
}
ulogsys << "(default terminate): wait done.." << endl << flush;
#if 1
if( g_term_thread && g_term_thread->joinable() )
g_term_thread->join();
#else
if( g_doneevent )
{
std::unique_lock<std::mutex> locker(g_donemutex);
while( !g_done )
g_doneevent.wait(locker);
}
#endif
ulogsys << "(default terminate): wait done OK (good bye)" << endl << flush;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetActivator::term( int signo ) void UniSetActivator::term( int signo )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment