core: improve reactor::receive_signal()

receive_signal() uses the unordered map _signal_handlers (signo mapped to
signal_handler) to either register a signal or find an existing one, and
from there get a future from the promise associated with that signal.
The problem is _signal_handlers.emplace() being called unconditionally,
resulting in the constructor from signal_handler always being called to
needlessly re-register the same handler, even when the signo is already
inserted in the map.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
This commit is contained in:
Raphael S. Carvalho
2015-01-22 23:17:11 -02:00
committed by Avi Kivity
parent b250b53004
commit be7dbcbf50

View File

@@ -113,9 +113,9 @@ reactor::reactor()
keep_doing([this] {
return receive_signal(SIGALRM).then([this] {
_timer_promise.set_value();
_timer_promise = promise<>();
_timer_promise = promise<>();
});
});
}).or_terminate();
memory::set_reclaim_hook([this] (std::function<void ()> reclaim_fn) {
// push it in the front of the queue so we reclaim memory quickly
_pending_tasks.push_front(make_task([fn = std::move(reclaim_fn)] {
@@ -547,7 +547,10 @@ void reactor::exit(int ret) {
future<>
reactor::receive_signal(int signo) {
auto i = _signal_handlers.emplace(signo, signo).first;
auto i = _signal_handlers.find(signo);
if (i == _signal_handlers.end()) {
i = _signal_handlers.emplace(signo, signo).first;
}
signal_handler& sh = i->second;
return sh._promise.get_future();
}