From 3193d5c2d9c6935adba4d3866f7bb9ab1a85396a Mon Sep 17 00:00:00 2001 From: Arseny Smirnov Date: Tue, 23 Apr 2019 10:42:46 +0300 Subject: [PATCH] Client: use several threads for multiple clients GitOrigin-RevId: 180f2977371a5a13b35ca929918450f88efcfec5 --- td/telegram/Client.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/td/telegram/Client.cpp b/td/telegram/Client.cpp index 7ad4f4fd..b9e7d6d4 100644 --- a/td/telegram/Client.cpp +++ b/td/telegram/Client.cpp @@ -139,8 +139,13 @@ class MultiImpl { public: static std::shared_ptr get() { static std::mutex mutex; - static std::weak_ptr impl; + static std::vector > impls; std::unique_lock lock(mutex); + if (impls.size() == 0) { + impls.resize(clamp(thread::hardware_concurrency(), 8u, 1000u) * 5 / 4); + } + auto &impl = *std::min_element(impls.begin(), impls.end(), + [](auto &a, auto &b) { return a.lock().use_count() < b.lock().use_count(); }); auto res = impl.lock(); if (!res) { res = std::make_shared();