Client: use several threads for multiple clients

GitOrigin-RevId: 180f2977371a5a13b35ca929918450f88efcfec5
This commit is contained in:
Arseny Smirnov 2019-04-23 10:42:46 +03:00
parent 176e7ea95f
commit 3193d5c2d9

View File

@ -139,8 +139,13 @@ class MultiImpl {
public:
static std::shared_ptr<MultiImpl> get() {
static std::mutex mutex;
static std::weak_ptr<MultiImpl> impl;
static std::vector<std::weak_ptr<MultiImpl> > impls;
std::unique_lock<std::mutex> 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<MultiImpl>();