From c7f3c3135550eb14abdc8b4241ee35e62b60c0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Sun, 17 Jan 2021 20:06:53 -0500 Subject: [PATCH] call: hangup subcalls on io thread Change-Id: Id382d9c31b62c233af3561f0f33132d1a346e0d8 --- src/call.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/call.cpp b/src/call.cpp index af03cea71d..757992842c 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -36,6 +36,8 @@ #include "errno.h" +#include <opendht/thread_pool.h> + #include <stdexcept> #include <system_error> #include <algorithm> @@ -50,33 +52,28 @@ namespace jami { /// calls the unary predicate \a pred with this call pointer and hangup the call with given error /// code \a errcode when the predicate return true. /// The predicate should have <code>bool(Call*) signature</code>. +template<typename T> inline void -hangupCallsIf(const Call::SubcallSet& callptr_list, +hangupCallsIf(Call::SubcallSet&& calls, int errcode, - const std::function<bool(Call*)>& pred) + T pred) { - std::for_each(std::begin(callptr_list), - std::end(callptr_list), - [&](const std::shared_ptr<Call>& call_ptr) { - if (pred(call_ptr.get())) { - try { - call_ptr->hangup(errcode); - } catch (const std::exception& e) { - JAMI_ERR("[call:%s] hangup failed: %s", - call_ptr->getCallId().c_str(), - e.what()); - } - } - }); + for (auto& call : calls) { + if (not pred(call.get())) + continue; + dht::ThreadPool::io().run([call = std::move(call), errcode] { + call->hangup(errcode); + }); + } } /// Hangup many calls with same error code. /// /// Works as hangupCallsIf() with a predicate that always return true. inline void -hangupCalls(const Call::SubcallSet& callptr_list, int errcode) +hangupCalls(Call::SubcallSet&& callptr_list, int errcode) { - hangupCallsIf(callptr_list, errcode, [](Call*) { return true; }); + hangupCallsIf(std::move(callptr_list), errcode, [](Call*) { return true; }); } //============================================================================== -- GitLab