Commit 5264b40b authored by Pavel Vainerman's avatar Pavel Vainerman

(CommonEventLoop): переделал процесс старта (evrun)

parent 0a13cee8
......@@ -182,7 +182,10 @@ int main( int argc, char** argv )
if( !ls.isRunning() )
{
cerr << "LOG SERVER NOT RUNNING!!" << endl;
return 1;
}
unsigned int i = 0;
......
......@@ -511,6 +511,9 @@ rm -f %buildroot%_libdir/*.la
* Tue Sep 12 2017 Alexei Takaseev <taf@altlinux.org> 2.6-alt19.1
- Rebuild with poco 1.7.9
# * Tue May 30 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt23.1
# - CommonEventLoop refactring start process
# * Mon May 29 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt23
# - (Configuration): add getStartapIgnoreTimeout()
# - minor fixes
......
......@@ -76,7 +76,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const
int recvTimeout = conf->getArgPInt("--" + prefix + "-recv-timeout", it.getProp("recvTimeout"), 5000);
int prepareTime = conf->getArgPInt("--" + prefix + "-prepare-time", it.getProp("prepareTime"), 2000);
int evrunTimeout = conf->getArgPInt("--" + prefix + "-evrun-timeout", it.getProp("evrunTimeout"), 40000);
int evrunTimeout = conf->getArgPInt("--" + prefix + "-evrun-timeout", it.getProp("evrunTimeout"), 60000);
int recvpause = conf->getArgPInt("--" + prefix + "-recvpause", it.getProp("recvpause"), 10);
int sendpause = conf->getArgPInt("--" + prefix + "-sendpause", it.getProp("sendpause"), 100);
int updatepause = conf->getArgPInt("--" + prefix + "-updatepause", it.getProp("updatepause"), 100);
......
......@@ -67,7 +67,7 @@ namespace uniset
* Даже если thread = false, но wather не сможет быть "активирован" функция вернёт управление
* с return false.
*/
bool evrun( EvWatcher* w, bool thread = true, size_t waitPrepareTimeout_msec = 5000);
bool evrun( EvWatcher* w, bool thread = true, size_t waitPrepareTimeout_msec = 60000);
/*! \return TRUE - если это был последний EvWatcher и loop остановлен */
bool evstop( EvWatcher* w );
......@@ -86,9 +86,10 @@ namespace uniset
void onStop( ev::async& w, int revents ) noexcept;
void onPrepare( ev::async& w, int revents ) noexcept;
void defaultLoop( std::promise<bool>& runOK ) noexcept;
void defaultLoop() noexcept;
bool runDefaultLoop( size_t waitTimeout_msec );
bool activateWatcher( EvWatcher* w, size_t waitTimeout_msec );
void onLoopOK( ev::timer& t, int revents ) noexcept;
std::atomic_bool cancelled = { false };
std::atomic_bool isrunning = { false };
......@@ -118,6 +119,11 @@ namespace uniset
std::queue<WatcherInfo> wactlist;
std::mutex wact_mutex;
ev::async evprep;
std::mutex looprunOK_mutex;
std::condition_variable looprunOK_event;
std::atomic_bool looprunOK_state;
ev::timer evruntimer;
};
// -------------------------------------------------------------------------
} // end of uniset namespace
......
......@@ -15,6 +15,9 @@ namespace uniset
evprep.set(loop);
evprep.set<CommonEventLoop, &CommonEventLoop::onPrepare>(this);
evruntimer.set(loop);
evruntimer.set<CommonEventLoop, &CommonEventLoop::onLoopOK>(this);
}
// -------------------------------------------------------------------------
CommonEventLoop::~CommonEventLoop()
......@@ -38,31 +41,15 @@ namespace uniset
if( thr )
return true;
bool defaultLoopOK = true;
std::promise<bool> pRun;
auto runOK = pRun.get_future();
thr = make_shared<std::thread>( [ &pRun, this ] { CommonEventLoop::defaultLoop(pRun); } );
// ожидание старта потока
while( true )
{
auto status = runOK.wait_for(std::chrono::milliseconds(waitTimeout_msec));
if( status == future_status::timeout )
{
defaultLoopOK = false;
break;
}
thr = make_shared<std::thread>( [&] { CommonEventLoop::defaultLoop(); } );
if( status == future_status::ready )
std::unique_lock<std::mutex> lock2(looprunOK_mutex);
looprunOK_event.wait_for(lock2, std::chrono::milliseconds(waitTimeout_msec), [&]()
{
defaultLoopOK = runOK.get();
break;
}
}
return (looprunOK_state == true);
} );
return defaultLoopOK;
return looprunOK_state;
}
// ---------------------------------------------------------------------------
bool CommonEventLoop::activateWatcher( EvWatcher* w, size_t waitTimeout_msec )
......@@ -78,6 +65,9 @@ namespace uniset
bool ret = true;
if( !evprep.is_active() )
evprep.start();
// посылаем сигнал для обработки
evprep.send(); // будим default loop
......@@ -101,6 +91,16 @@ namespace uniset
return ret;
}
// ---------------------------------------------------------------------------
void CommonEventLoop::onLoopOK( ev::timer& t, int revents ) noexcept
{
if( EV_ERROR & revents )
return;
looprunOK_state = true;
looprunOK_event.notify_all();
t.stop();
}
// ---------------------------------------------------------------------------
bool CommonEventLoop::evrun( EvWatcher* w, bool thread, size_t waitTimeout_msec )
{
if( w == nullptr )
......@@ -249,14 +249,16 @@ namespace uniset
}
// -------------------------------------------------------------------------
void CommonEventLoop::defaultLoop( std::promise<bool>& runOK ) noexcept
void CommonEventLoop::defaultLoop() noexcept
{
evterm.start();
evprep.start();
isrunning = true;
// делаем очень маленькое время старта
// т.к. нам надо просто зафиксировать, что loop начал работать
evruntimer.start(0, 0.001);
runOK.set_value(true);
isrunning = true;
while( !cancelled )
{
......
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