From be7dbcbf50dd90c140ee73aee5e315abe4c4337e Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Thu, 22 Jan 2015 23:17:11 -0200 Subject: [PATCH] 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 --- core/reactor.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/reactor.cc b/core/reactor.cc index 791f00e374..c2401e6af2 100644 --- a/core/reactor.cc +++ b/core/reactor.cc @@ -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 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(); }