From 238769f5eb38ad8397ec783cfb4640d4524efd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Wed, 12 Aug 2020 11:37:28 +0200 Subject: [PATCH] F #4936: Execute listener action outside lock (#148) --- include/Listener.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/Listener.h b/include/Listener.h index ab0ebcf6d6..e7ef825d04 100644 --- a/include/Listener.h +++ b/include/Listener.h @@ -162,19 +162,23 @@ protected: { end = false; - std::unique_lock ul(lock); - while (true) { - cond.wait(ul, [&]{return (end || !pending.empty());}); + std::function fn; - if (end) { - break; - } + std::unique_lock ul(lock); - auto fn = pending.front(); - pending.pop(); + cond.wait(ul, [&]{return (end || !pending.empty());}); + + if (end) + { + break; + } + + fn = pending.front(); + pending.pop(); + } fn(); }