[ios,macos,android,qt] use shared threadpool
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
14
platform/default/mbgl/util/shared_thread_pool.cpp
Normal file
14
platform/default/mbgl/util/shared_thread_pool.cpp
Normal 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
|
||||
9
platform/default/mbgl/util/shared_thread_pool.hpp
Normal file
9
platform/default/mbgl/util/shared_thread_pool.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/util/default_thread_pool.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
std::shared_ptr<ThreadPool> sharedThreadPool();
|
||||
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user