[ios,macos,android,qt] use shared threadpool

This commit is contained in:
Konstantin Käfer
2017-02-20 14:59:17 +01:00
parent 4e752f63b9
commit 3ef9e26593
13 changed files with 52 additions and 22 deletions

View File

@@ -1,12 +1,16 @@
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/actor/mailbox.hpp>
#include <mbgl/util/platform.hpp>
#include <mbgl/util/string.hpp>
namespace mbgl {
ThreadPool::ThreadPool(std::size_t count) {
threads.reserve(count);
for (std::size_t i = 0; i < count; ++i) {
threads.emplace_back([this] () {
threads.emplace_back([this, i]() {
platform::setCurrentThreadName(std::string{ "Worker " } + util::toString(i + 1));
while (true) {
std::unique_lock<std::mutex> lock(mutex);

View File

@@ -0,0 +1,14 @@
#include "shared_thread_pool.hpp"
namespace mbgl {
std::shared_ptr<ThreadPool> sharedThreadPool() {
static std::weak_ptr<ThreadPool> weak;
auto pool = weak.lock();
if (!pool) {
weak = pool = std::make_shared<ThreadPool>(4);
}
return pool;
}
} // namespace mbgl

View File

@@ -0,0 +1,9 @@
#pragma once
#include <mbgl/util/default_thread_pool.hpp>
namespace mbgl {
std::shared_ptr<ThreadPool> sharedThreadPool();
} // namespace mbgl