Commit cdcaf04b authored by Pavel Vainerman's avatar Pavel Vainerman

(CommonEventLoop): переделал на активацию только одного за один раз

(вместо списка)
parent 025bed32
......@@ -16,7 +16,7 @@
Name: libuniset2
Version: 2.6
Release: alt26
Release: alt27
Summary: UniSet - library for building distributed industrial control systems
License: LGPL
......@@ -508,6 +508,9 @@ rm -f %buildroot%_libdir/*.la
# history of current unpublished changes
%changelog
* Thu Jun 01 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt27
- test build (devel)
* Thu Jun 01 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt26
- test build (devel)
......
......@@ -116,7 +116,7 @@ namespace uniset
std::promise<bool>& result;
};
std::queue<WatcherInfo> wactlist;
std::shared_ptr<WatcherInfo> wact_info = { nullptr };
std::mutex wact_mutex;
ev::async evprep;
......
......@@ -54,17 +54,18 @@ namespace uniset
// ---------------------------------------------------------------------------
bool CommonEventLoop::activateWatcher( EvWatcher* w, size_t waitTimeout_msec )
{
std::lock_guard<std::mutex> l(wact_mutex);
std::promise<bool> p;
WatcherInfo winfo(w,p);
auto result = p.get_future();
wact_info = std::make_shared<WatcherInfo>(w,p);
{
std::unique_lock<std::mutex> l(wact_mutex);
wactlist.push(winfo);
}
auto result = p.get_future();
bool ret = true;
if( !evprep.is_active() )
evprep.start();
// посылаем сигнал для обработки
evprep.send(); // будим default loop
......@@ -88,6 +89,7 @@ namespace uniset
}
}
wact_info = nullptr;
return ret;
}
// ---------------------------------------------------------------------------
......@@ -196,25 +198,18 @@ namespace uniset
return;
}
{
std::lock_guard<std::mutex> lock(wact_mutex);
while( !wactlist.empty() )
{
auto winf = wactlist.front();
wactlist.pop();
if( !wact_info )
return;
try
{
winf.watcher->evprepare(loop);
winf.result.set_value(true);
wact_info->watcher->evprepare(loop);
wact_info->result.set_value(true);
}
catch( std::exception& ex )
{
cerr << "(CommonEventLoop::onPrepare): evprepare err: " << ex.what() << endl;
winf.result.set_value(false);
}
}
wact_info->result.set_value(false);
}
}
// -------------------------------------------------------------------------
......
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