summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2019-02-14 16:56:17 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2019-05-10 14:20:38 +0300
commit06f1dc48a2fb317979ab48ce323115be5bd48f16 (patch)
tree5ef1e78a1f98a7a26034ca519e267bda235b2817 /platform
parent947bc75f56fae7f1e70f21b98730dc6b460b9194 (diff)
downloadqtlocation-mapboxgl-06f1dc48a2fb317979ab48ce323115be5bd48f16.tar.gz
[core] Make the BackgroundScheduler a singleton
- Do not carry it over everywhere as parameter, it is a shared instance anyway and the lifecycle is pretty much the app lifecycle from the moment we instantiate a map. - Rename to BackgroundScheduler because it is a Scheduler that will do tasks in the background, we don't make assumptions if it is a thread pool or a single thread. - Most importantly, remove the dependency from `core` on `platform`.
Diffstat (limited to 'platform')
-rw-r--r--platform/android/core-files.json6
-rw-r--r--platform/android/src/map_renderer.cpp4
-rwxr-xr-xplatform/android/src/native_map_view.cpp6
-rwxr-xr-xplatform/android/src/native_map_view.hpp2
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp7
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.hpp2
-rw-r--r--platform/android/src/style/sources/geojson_source.cpp7
-rw-r--r--platform/darwin/src/MGLMapSnapshotter.mm8
-rw-r--r--platform/default/include/mbgl/gl/headless_frontend.hpp3
-rw-r--r--platform/default/include/mbgl/map/map_snapshotter.hpp3
-rw-r--r--platform/default/include/mbgl/util/default_thread_pool.hpp27
-rw-r--r--platform/default/include/mbgl/util/shared_thread_pool.hpp9
-rw-r--r--platform/default/src/mbgl/gl/headless_frontend.cpp6
-rw-r--r--platform/default/src/mbgl/map/map_snapshotter.cpp18
-rw-r--r--platform/default/src/mbgl/util/default_thread_pool.cpp57
-rw-r--r--platform/default/src/mbgl/util/shared_thread_pool.cpp14
-rw-r--r--platform/glfw/main.cpp7
-rw-r--r--platform/ios/core-files.json6
-rw-r--r--platform/ios/src/MGLMapView.mm10
-rw-r--r--platform/linux/config.cmake5
-rw-r--r--platform/macos/core-files.json6
-rw-r--r--platform/macos/src/MGLMapView.mm8
-rw-r--r--platform/node/src/node_map.cpp8
-rw-r--r--platform/node/src/node_map.hpp3
-rw-r--r--platform/node/src/node_thread_pool.cpp12
-rw-r--r--platform/qt/qt.cmake6
-rw-r--r--platform/qt/src/qmapboxgl.cpp5
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.cpp4
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.hpp3
-rw-r--r--platform/qt/src/qmapboxgl_p.hpp2
-rw-r--r--platform/qt/src/qmapboxgl_renderer_backend.hpp1
31 files changed, 47 insertions, 218 deletions
diff --git a/platform/android/core-files.json b/platform/android/core-files.json
index 20dcc12c7d..ba56695bdd 100644
--- a/platform/android/core-files.json
+++ b/platform/android/core-files.json
@@ -89,9 +89,7 @@
"platform/default/src/mbgl/gl/headless_frontend.cpp",
"platform/default/src/mbgl/map/map_snapshotter.cpp",
"platform/default/src/mbgl/text/bidi.cpp",
- "platform/default/src/mbgl/util/default_thread_pool.cpp",
"platform/default/src/mbgl/util/png_writer.cpp",
- "platform/default/src/mbgl/util/shared_thread_pool.cpp",
"platform/default/src/mbgl/util/thread_local.cpp",
"platform/default/src/mbgl/util/utf.cpp",
"platform/linux/src/headless_backend_egl.cpp"
@@ -101,9 +99,7 @@
"mbgl/gl/headless_backend.hpp": "platform/default/include/mbgl/gl/headless_backend.hpp",
"mbgl/gl/headless_frontend.hpp": "platform/default/include/mbgl/gl/headless_frontend.hpp",
"mbgl/map/map_snapshotter.hpp": "platform/default/include/mbgl/map/map_snapshotter.hpp",
- "mbgl/text/unaccent.hpp": "platform/default/include/mbgl/text/unaccent.hpp",
- "mbgl/util/default_thread_pool.hpp": "platform/default/include/mbgl/util/default_thread_pool.hpp",
- "mbgl/util/shared_thread_pool.hpp": "platform/default/include/mbgl/util/shared_thread_pool.hpp"
+ "mbgl/text/unaccent.hpp": "platform/default/include/mbgl/text/unaccent.hpp"
},
"private_headers": {
"android_renderer_backend.hpp": "platform/android/src/android_renderer_backend.hpp",
diff --git a/platform/android/src/map_renderer.cpp b/platform/android/src/map_renderer.cpp
index 64c00585f8..92444c404d 100644
--- a/platform/android/src/map_renderer.cpp
+++ b/platform/android/src/map_renderer.cpp
@@ -2,7 +2,6 @@
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/gfx/backend_scope.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <string>
@@ -23,7 +22,6 @@ MapRenderer::MapRenderer(jni::JNIEnv& _env,
, pixelRatio(pixelRatio_)
, programCacheDir(jni::Make<std::string>(_env, programCacheDir_))
, localIdeographFontFamily(localIdeographFontFamily_ ? jni::Make<std::string>(_env, localIdeographFontFamily_) : optional<std::string>{})
- , threadPool(sharedThreadPool())
, mailbox(std::make_shared<Mailbox>(*this)) {
}
@@ -175,7 +173,7 @@ void MapRenderer::onSurfaceCreated(JNIEnv&) {
// Create the new backend and renderer
backend = std::make_unique<AndroidRendererBackend>();
- renderer = std::make_unique<Renderer>(*backend, pixelRatio, *threadPool, programCacheDir, localIdeographFontFamily);
+ renderer = std::make_unique<Renderer>(*backend, pixelRatio, programCacheDir, localIdeographFontFamily);
rendererRef = std::make_unique<ActorRef<Renderer>>(*renderer, mailbox);
// Set the observer on the new Renderer implementation
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 8f1ec9c576..ae53bcc802 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -21,7 +21,6 @@
#include <mbgl/util/exception.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/image.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
#include <mbgl/util/projection.hpp>
@@ -66,8 +65,7 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
jni::jboolean _crossSourceCollisions)
: javaPeer(_env, _obj)
, mapRenderer(MapRenderer::getNativePeer(_env, jMapRenderer))
- , pixelRatio(_pixelRatio)
- , threadPool(sharedThreadPool()) {
+ , pixelRatio(_pixelRatio) {
// Get a reference to the JavaVM for callbacks
if (_env.GetJavaVM(&vm) < 0) {
@@ -89,7 +87,7 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
// Create the core map
map = std::make_unique<mbgl::Map>(
- *rendererFrontend, *this, *threadPool, options,
+ *rendererFrontend, *this, options,
mbgl::android::FileSource::getSharedResourceOptions(_env, jFileSource));
}
diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp
index c9ba6089c3..9e6ad73dd7 100755
--- a/platform/android/src/native_map_view.hpp
+++ b/platform/android/src/native_map_view.hpp
@@ -4,7 +4,6 @@
#include <mbgl/map/camera.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/storage/network_status.hpp>
@@ -258,7 +257,6 @@ private:
int height = 64;
// Ensure these are initialised last
- std::shared_ptr<mbgl::ThreadPool> threadPool;
std::unique_ptr<mbgl::Map> map;
mbgl::EdgeInsets insets;
};
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp
index 47a2781cb5..2eca6595e1 100644
--- a/platform/android/src/snapshotter/map_snapshotter.cpp
+++ b/platform/android/src/snapshotter/map_snapshotter.cpp
@@ -2,7 +2,6 @@
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/actor/scheduler.hpp>
@@ -27,8 +26,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
const jni::String& _programCacheDir,
const jni::String& _localIdeographFontFamily)
: javaPeer(_env, _obj)
- , pixelRatio(_pixelRatio)
- , threadPool(sharedThreadPool()) {
+ , pixelRatio(_pixelRatio) {
// Get a reference to the JavaVM for callbacks
if (_env.GetJavaVM(&vm) < 0) {
@@ -58,8 +56,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env,
showLogo = _showLogo;
// Create the core snapshotter
- snapshotter = std::make_unique<mbgl::MapSnapshotter>(threadPool,
- style,
+ snapshotter = std::make_unique<mbgl::MapSnapshotter>(style,
size,
pixelRatio,
cameraOptions,
diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp
index e8c0885ff1..791aa61d6a 100644
--- a/platform/android/src/snapshotter/map_snapshotter.hpp
+++ b/platform/android/src/snapshotter/map_snapshotter.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/map/map_snapshotter.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/util.hpp>
#include "../file_source.hpp"
@@ -63,7 +62,6 @@ private:
float pixelRatio;
bool showLogo;
- std::shared_ptr<mbgl::ThreadPool> threadPool;
std::unique_ptr<Actor<mbgl::MapSnapshotter::Callback>> snapshotCallback;
std::unique_ptr<mbgl::MapSnapshotter> snapshotter;
diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp
index a9307afe67..5ff4864275 100644
--- a/platform/android/src/style/sources/geojson_source.cpp
+++ b/platform/android/src/style/sources/geojson_source.cpp
@@ -17,7 +17,6 @@
#include "../conversion/url_or_tileset.hpp"
#include <string>
-#include <mbgl/util/shared_thread_pool.hpp>
// GeoJSONSource uses a "coalescing" model for high frequency asynchronous data update calls,
// which in practice means, that any update that started processing is going to finish
@@ -48,16 +47,14 @@ namespace android {
: Source(env, std::make_unique<mbgl::style::GeoJSONSource>(
jni::Make<std::string>(env, sourceId),
convertGeoJSONOptions(env, options)))
- , threadPool(sharedThreadPool())
- , converter(std::make_unique<Actor<FeatureConverter>>(*threadPool)) {
+ , converter(std::make_unique<Actor<FeatureConverter>>(Scheduler::GetBackground())) {
}
GeoJSONSource::GeoJSONSource(jni::JNIEnv& env,
mbgl::style::Source& coreSource,
AndroidRendererFrontend& frontend)
: Source(env, coreSource, createJavaPeer(env), frontend)
- , threadPool(sharedThreadPool())
- , converter(std::make_unique<Actor<FeatureConverter>>(*threadPool)) {
+ , converter(std::make_unique<Actor<FeatureConverter>>(Scheduler::GetBackground())) {
}
GeoJSONSource::~GeoJSONSource() = default;
diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm
index 171f24e4d0..65bed2cf42 100644
--- a/platform/darwin/src/MGLMapSnapshotter.mm
+++ b/platform/darwin/src/MGLMapSnapshotter.mm
@@ -8,9 +8,7 @@
#import <mbgl/map/camera.hpp>
#import <mbgl/storage/resource_options.hpp>
#import <mbgl/storage/default_file_source.hpp>
-#import <mbgl/util/default_thread_pool.hpp>
#import <mbgl/util/string.hpp>
-#import <mbgl/util/shared_thread_pool.hpp>
#import "MGLOfflineStorage_Private.h"
#import "MGLGeometry_Private.h"
@@ -125,7 +123,6 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
@end
@implementation MGLMapSnapshotter {
- std::shared_ptr<mbgl::ThreadPool> _mbglThreadPool;
std::unique_ptr<mbgl::MapSnapshotter> _mbglMapSnapshotter;
std::unique_ptr<mbgl::Actor<mbgl::MapSnapshotter::Callback>> _snapshotCallback;
}
@@ -176,7 +173,6 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
_mbglMapSnapshotter.reset();
_snapshotCallback.reset();
- _mbglThreadPool.reset();
self.terminated = YES;
}
@@ -591,8 +587,6 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
_options = options;
auto mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
-
- _mbglThreadPool = mbgl::sharedThreadPool();
std::string styleURL = std::string([options.styleURL.absoluteString UTF8String]);
std::pair<bool, std::string> style = std::make_pair(false, styleURL);
@@ -630,7 +624,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64;
// Create the snapshotter
_mbglMapSnapshotter = std::make_unique<mbgl::MapSnapshotter>(
- _mbglThreadPool, style, size, pixelRatio, cameraOptions, coordinateBounds, config.cacheDir, config.localFontFamilyName, resourceOptions);
+ style, size, pixelRatio, cameraOptions, coordinateBounds, config.cacheDir, config.localFontFamilyName, resourceOptions);
}
@end
diff --git a/platform/default/include/mbgl/gl/headless_frontend.hpp b/platform/default/include/mbgl/gl/headless_frontend.hpp
index ff733f423d..1e693bdef1 100644
--- a/platform/default/include/mbgl/gl/headless_frontend.hpp
+++ b/platform/default/include/mbgl/gl/headless_frontend.hpp
@@ -10,7 +10,6 @@
namespace mbgl {
-class Scheduler;
class Renderer;
class Map;
class TransformState;
@@ -22,13 +21,11 @@ class RendererBackend;
class HeadlessFrontend : public RendererFrontend {
public:
HeadlessFrontend(float pixelRatio_,
- Scheduler&,
const optional<std::string> programCacheDir = {},
gfx::ContextMode mode = gfx::ContextMode::Unique,
const optional<std::string> localFontFamily = {});
HeadlessFrontend(Size,
float pixelRatio_,
- Scheduler&,
const optional<std::string> programCacheDir = {},
gfx::ContextMode mode = gfx::ContextMode::Unique,
const optional<std::string> localFontFamily = {});
diff --git a/platform/default/include/mbgl/map/map_snapshotter.hpp b/platform/default/include/mbgl/map/map_snapshotter.hpp
index ccc3ee17f7..db1ba1f267 100644
--- a/platform/default/include/mbgl/map/map_snapshotter.hpp
+++ b/platform/default/include/mbgl/map/map_snapshotter.hpp
@@ -26,8 +26,7 @@ class Style;
class MapSnapshotter {
public:
- MapSnapshotter(std::shared_ptr<Scheduler> scheduler,
- const std::pair<bool, std::string> style,
+ MapSnapshotter(const std::pair<bool, std::string> style,
const Size&,
const float pixelRatio,
const optional<CameraOptions> cameraOptions,
diff --git a/platform/default/include/mbgl/util/default_thread_pool.hpp b/platform/default/include/mbgl/util/default_thread_pool.hpp
deleted file mode 100644
index a14d16d771..0000000000
--- a/platform/default/include/mbgl/util/default_thread_pool.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once
-
-#include <mbgl/actor/scheduler.hpp>
-
-#include <condition_variable>
-#include <mutex>
-#include <queue>
-#include <thread>
-
-namespace mbgl {
-
-class ThreadPool : public Scheduler {
-public:
- ThreadPool(std::size_t count);
- ~ThreadPool() override;
-
- void schedule(std::weak_ptr<Mailbox>) override;
-
-private:
- std::vector<std::thread> threads;
- std::queue<std::weak_ptr<Mailbox>> queue;
- std::mutex mutex;
- std::condition_variable cv;
- bool terminate { false };
-};
-
-} // namespace mbgl
diff --git a/platform/default/include/mbgl/util/shared_thread_pool.hpp b/platform/default/include/mbgl/util/shared_thread_pool.hpp
deleted file mode 100644
index 04a3cb58d5..0000000000
--- a/platform/default/include/mbgl/util/shared_thread_pool.hpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-
-#include <mbgl/util/default_thread_pool.hpp>
-
-namespace mbgl {
-
-std::shared_ptr<ThreadPool> sharedThreadPool();
-
-} // namespace mbgl
diff --git a/platform/default/src/mbgl/gl/headless_frontend.cpp b/platform/default/src/mbgl/gl/headless_frontend.cpp
index 7e56996f63..101028b5c8 100644
--- a/platform/default/src/mbgl/gl/headless_frontend.cpp
+++ b/platform/default/src/mbgl/gl/headless_frontend.cpp
@@ -10,17 +10,15 @@
namespace mbgl {
HeadlessFrontend::HeadlessFrontend(float pixelRatio_,
- Scheduler& scheduler,
const optional<std::string> programCacheDir,
const gfx::ContextMode contextMode,
const optional<std::string> localFontFamily)
: HeadlessFrontend(
- { 256, 256 }, pixelRatio_, scheduler, programCacheDir, contextMode, localFontFamily) {
+ { 256, 256 }, pixelRatio_, programCacheDir, contextMode, localFontFamily) {
}
HeadlessFrontend::HeadlessFrontend(Size size_,
float pixelRatio_,
- Scheduler& scheduler,
const optional<std::string> programCacheDir,
const gfx::ContextMode contextMode,
const optional<std::string> localFontFamily)
@@ -40,7 +38,7 @@ HeadlessFrontend::HeadlessFrontend(Size size_,
renderer->render(*updateParameters_);
}
}),
- renderer(std::make_unique<Renderer>(backend, pixelRatio, scheduler, programCacheDir, localFontFamily)) {
+ renderer(std::make_unique<Renderer>(backend, pixelRatio, programCacheDir, localFontFamily)) {
}
HeadlessFrontend::~HeadlessFrontend() = default;
diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp
index 6e02ac8532..7bfa2462a0 100644
--- a/platform/default/src/mbgl/map/map_snapshotter.cpp
+++ b/platform/default/src/mbgl/map/map_snapshotter.cpp
@@ -14,8 +14,7 @@ namespace mbgl {
class MapSnapshotter::Impl {
public:
- Impl(std::shared_ptr<Scheduler>,
- const std::pair<bool, std::string> style,
+ Impl(const std::pair<bool, std::string> style,
const Size&,
const float pixelRatio,
const optional<CameraOptions> cameraOptions,
@@ -42,13 +41,11 @@ public:
void snapshot(ActorRef<MapSnapshotter::Callback>);
private:
- std::shared_ptr<Scheduler> scheduler;
HeadlessFrontend frontend;
Map map;
};
-MapSnapshotter::Impl::Impl(std::shared_ptr<Scheduler> scheduler_,
- const std::pair<bool, std::string> style,
+MapSnapshotter::Impl::Impl(const std::pair<bool, std::string> style,
const Size& size,
const float pixelRatio,
const optional<CameraOptions> cameraOptions,
@@ -56,12 +53,10 @@ MapSnapshotter::Impl::Impl(std::shared_ptr<Scheduler> scheduler_,
const optional<std::string> programCacheDir,
const optional<std::string> localFontFamily,
const ResourceOptions& resourceOptions)
- : scheduler(std::move(scheduler_)),
- frontend(
- size, pixelRatio, *scheduler, programCacheDir, gfx::ContextMode::Unique, localFontFamily),
+ : frontend(
+ size, pixelRatio, programCacheDir, gfx::ContextMode::Unique, localFontFamily),
map(frontend,
MapObserver::nullObserver(),
- *scheduler,
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
resourceOptions) {
if (style.first) {
@@ -168,8 +163,7 @@ LatLngBounds MapSnapshotter::Impl::getRegion() const {
return map.latLngBoundsForCamera(getCameraOptions());
}
-MapSnapshotter::MapSnapshotter(std::shared_ptr<Scheduler> scheduler,
- const std::pair<bool, std::string> style,
+MapSnapshotter::MapSnapshotter(const std::pair<bool, std::string> style,
const Size& size,
const float pixelRatio,
const optional<CameraOptions> cameraOptions,
@@ -178,7 +172,7 @@ MapSnapshotter::MapSnapshotter(std::shared_ptr<Scheduler> scheduler,
const optional<std::string> localFontFamily,
const ResourceOptions& resourceOptions)
: impl(std::make_unique<util::Thread<MapSnapshotter::Impl>>(
- "Map Snapshotter", std::move(scheduler), style, size, pixelRatio, cameraOptions,
+ "Map Snapshotter", style, size, pixelRatio, cameraOptions,
region, programCacheDir, localFontFamily, resourceOptions.clone())) {}
MapSnapshotter::~MapSnapshotter() = default;
diff --git a/platform/default/src/mbgl/util/default_thread_pool.cpp b/platform/default/src/mbgl/util/default_thread_pool.cpp
deleted file mode 100644
index d3950bb8aa..0000000000
--- a/platform/default/src/mbgl/util/default_thread_pool.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#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, i]() {
- platform::setCurrentThreadName(std::string{ "Worker " } + util::toString(i + 1));
-
- while (true) {
- std::unique_lock<std::mutex> lock(mutex);
-
- cv.wait(lock, [this] {
- return !queue.empty() || terminate;
- });
-
- if (terminate) {
- return;
- }
-
- auto mailbox = queue.front();
- queue.pop();
- lock.unlock();
-
- Mailbox::maybeReceive(mailbox);
- }
- });
- }
-}
-
-ThreadPool::~ThreadPool() {
- {
- std::lock_guard<std::mutex> lock(mutex);
- terminate = true;
- }
-
- cv.notify_all();
-
- for (auto& thread : threads) {
- thread.join();
- }
-}
-
-void ThreadPool::schedule(std::weak_ptr<Mailbox> mailbox) {
- {
- std::lock_guard<std::mutex> lock(mutex);
- queue.push(mailbox);
- }
-
- cv.notify_one();
-}
-
-} // namespace mbgl
diff --git a/platform/default/src/mbgl/util/shared_thread_pool.cpp b/platform/default/src/mbgl/util/shared_thread_pool.cpp
deleted file mode 100644
index d7facbab94..0000000000
--- a/platform/default/src/mbgl/util/shared_thread_pool.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <mbgl/util/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
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 4e631ec895..04cff3962a 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -5,7 +5,6 @@
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/style/style.hpp>
@@ -109,10 +108,9 @@ int main(int argc, char *argv[]) {
mbgl::Log::Warning(mbgl::Event::Setup, "Application is offline. Press `O` to toggle online status.");
}
- mbgl::ThreadPool threadPool(4);
- GLFWRendererFrontend rendererFrontend { std::make_unique<mbgl::Renderer>(view->getRendererBackend(), view->getPixelRatio(), threadPool), *view };
+ GLFWRendererFrontend rendererFrontend { std::make_unique<mbgl::Renderer>(view->getRendererBackend(), view->getPixelRatio()), *view };
- mbgl::Map map(rendererFrontend, *view, threadPool,
+ mbgl::Map map(rendererFrontend, *view,
mbgl::MapOptions().withSize(view->getSize()).withPixelRatio(view->getPixelRatio()), resourceOptions);
backend.setMap(&map);
@@ -199,5 +197,6 @@ int main(int argc, char *argv[]) {
settings.latitude, settings.longitude, settings.zoom, settings.bearing);
view = nullptr;
+
return 0;
}
diff --git a/platform/ios/core-files.json b/platform/ios/core-files.json
index c3e54a45b0..98833b0c94 100644
--- a/platform/ios/core-files.json
+++ b/platform/ios/core-files.json
@@ -14,9 +14,7 @@
"platform/default/src/mbgl/gl/headless_frontend.cpp",
"platform/default/src/mbgl/map/map_snapshotter.cpp",
"platform/default/src/mbgl/text/bidi.cpp",
- "platform/default/src/mbgl/util/default_thread_pool.cpp",
"platform/default/src/mbgl/util/png_writer.cpp",
- "platform/default/src/mbgl/util/shared_thread_pool.cpp",
"platform/default/src/mbgl/util/thread_local.cpp",
"platform/default/src/mbgl/util/utf.cpp"
],
@@ -26,9 +24,7 @@
"mbgl/gl/headless_backend.hpp": "platform/default/include/mbgl/gl/headless_backend.hpp",
"mbgl/gl/headless_frontend.hpp": "platform/default/include/mbgl/gl/headless_frontend.hpp",
"mbgl/map/map_snapshotter.hpp": "platform/default/include/mbgl/map/map_snapshotter.hpp",
- "mbgl/util/default_styles.hpp": "platform/default/include/mbgl/util/default_styles.hpp",
- "mbgl/util/default_thread_pool.hpp": "platform/default/include/mbgl/util/default_thread_pool.hpp",
- "mbgl/util/shared_thread_pool.hpp": "platform/default/include/mbgl/util/shared_thread_pool.hpp"
+ "mbgl/util/default_styles.hpp": "platform/default/include/mbgl/util/default_styles.hpp"
},
"private_headers": {
"CFHandle.hpp": "platform/darwin/src/CFHandle.hpp"
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index a4f994a2f4..fa49a2f280 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -10,7 +10,6 @@
#include <mbgl/map/mode.hpp>
#include <mbgl/util/platform.hpp>
#include <mbgl/storage/reachability.h>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/style/style.hpp>
@@ -29,7 +28,6 @@
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/projection.hpp>
@@ -280,8 +278,6 @@ public:
MBGLView *_mbglView;
std::unique_ptr<MGLRenderFrontend> _rendererFrontend;
- std::shared_ptr<mbgl::ThreadPool> _mbglThreadPool;
-
BOOL _opaque;
MGLAnnotationTagContextMap _annotationContextsByAnnotationTag;
@@ -476,9 +472,8 @@ public:
// setup mbgl map
MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration];
- _mbglThreadPool = mbgl::sharedThreadPool();
- auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, *_mbglThreadPool, config.cacheDir, config.localFontFamilyName);
+ auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, config.cacheDir, config.localFontFamilyName);
BOOL enableCrossSourceCollisions = !config.perSourceCollisions;
_rendererFrontend = std::make_unique<MGLRenderFrontend>(std::move(renderer), self, *_mbglView);
@@ -495,7 +490,7 @@ public:
.withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String);
NSAssert(!_mbglMap, @"_mbglMap should be NULL");
- _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, *_mbglThreadPool, mapOptions, resourceOptions);
+ _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, mapOptions, resourceOptions);
// start paused if in IB
if (background) {
@@ -772,7 +767,6 @@ public:
_mbglView = nullptr;
_rendererFrontend.reset();
- _mbglThreadPool.reset();
}
- (void)dealloc
diff --git a/platform/linux/config.cmake b/platform/linux/config.cmake
index 4405e0583f..118dfe696c 100644
--- a/platform/linux/config.cmake
+++ b/platform/linux/config.cmake
@@ -72,11 +72,6 @@ macro(mbgl_platform_core)
# Snapshotting
PRIVATE platform/default/src/mbgl/map/map_snapshotter.cpp
PRIVATE platform/default/include/mbgl/map/map_snapshotter.hpp
-
- # Thread pool
- PRIVATE platform/default/src/mbgl/util/default_thread_pool.cpp
- PRIVATE platform/default/src/mbgl/util/default_thread_pool.cpp
- PRIVATE platform/default/src/mbgl/util/shared_thread_pool.cpp
)
target_include_directories(mbgl-core
diff --git a/platform/macos/core-files.json b/platform/macos/core-files.json
index 9ec41f651a..abeda5796b 100644
--- a/platform/macos/core-files.json
+++ b/platform/macos/core-files.json
@@ -13,9 +13,7 @@
"platform/default/src/mbgl/gl/headless_frontend.cpp",
"platform/default/src/mbgl/map/map_snapshotter.cpp",
"platform/default/src/mbgl/text/bidi.cpp",
- "platform/default/src/mbgl/util/default_thread_pool.cpp",
"platform/default/src/mbgl/util/png_writer.cpp",
- "platform/default/src/mbgl/util/shared_thread_pool.cpp",
"platform/default/src/mbgl/util/thread_local.cpp",
"platform/default/src/mbgl/util/utf.cpp"
],
@@ -24,9 +22,7 @@
"mbgl/util/image+MGLAdditions.hpp": "platform/darwin/include/mbgl/util/image+MGLAdditions.hpp",
"mbgl/gl/headless_backend.hpp": "platform/default/include/mbgl/gl/headless_backend.hpp",
"mbgl/gl/headless_frontend.hpp": "platform/default/include/mbgl/gl/headless_frontend.hpp",
- "mbgl/map/map_snapshotter.hpp": "platform/default/include/mbgl/map/map_snapshotter.hpp",
- "mbgl/util/default_thread_pool.hpp": "platform/default/include/mbgl/util/default_thread_pool.hpp",
- "mbgl/util/shared_thread_pool.hpp": "platform/default/include/mbgl/util/shared_thread_pool.hpp"
+ "mbgl/map/map_snapshotter.hpp": "platform/default/include/mbgl/map/map_snapshotter.hpp"
},
"private_headers": {
"CFHandle.hpp": "platform/darwin/src/CFHandle.hpp"
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index e9259cf907..77eb300aef 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -31,7 +31,6 @@
#import <mbgl/annotation/annotation.hpp>
#import <mbgl/map/camera.hpp>
#import <mbgl/storage/reachability.h>
-#import <mbgl/util/default_thread_pool.hpp>
#import <mbgl/style/image.hpp>
#import <mbgl/renderer/renderer.hpp>
#import <mbgl/gl/renderer_backend.hpp>
@@ -43,7 +42,6 @@
#import <mbgl/util/chrono.hpp>
#import <mbgl/util/exception.hpp>
#import <mbgl/util/run_loop.hpp>
-#import <mbgl/util/shared_thread_pool.hpp>
#import <mbgl/util/string.hpp>
#import <mbgl/util/projection.hpp>
@@ -164,7 +162,6 @@ public:
mbgl::Map *_mbglMap;
MGLMapViewImpl *_mbglView;
std::unique_ptr<MGLRenderFrontend> _rendererFrontend;
- std::shared_ptr<mbgl::ThreadPool> _mbglThreadPool;
NSPanGestureRecognizer *_panGestureRecognizer;
NSMagnificationGestureRecognizer *_magnificationGestureRecognizer;
@@ -283,10 +280,9 @@ public:
NSURL *legacyCacheURL = [cachesDirectoryURL URLByAppendingPathComponent:@"cache.db"];
[[NSFileManager defaultManager] removeItemAtURL:legacyCacheURL error:NULL];
- _mbglThreadPool = mbgl::sharedThreadPool();
MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration];
- auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, *_mbglThreadPool, config.cacheDir, config.localFontFamilyName);
+ auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, config.cacheDir, config.localFontFamilyName);
BOOL enableCrossSourceCollisions = !config.perSourceCollisions;
_rendererFrontend = std::make_unique<MGLRenderFrontend>(std::move(renderer), self, *_mbglView, true);
@@ -302,7 +298,7 @@ public:
resourceOptions.withCachePath([[MGLOfflineStorage sharedOfflineStorage] mbglCachePath])
.withAssetPath([NSBundle mainBundle].resourceURL.path.UTF8String);
- _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, *_mbglThreadPool, mapOptions, resourceOptions);
+ _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, mapOptions, resourceOptions);
// Install the OpenGL layer. Interface Builder’s synchronous drawing means
// we can’t display a map, so don’t even bother to have a map layer.
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 7156a1f1bf..0a7da3a83a 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -630,8 +630,8 @@ void NodeMap::cancel() {
reinterpret_cast<NodeMap *>(h->data)->renderFinished();
});
- frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio, threadpool);
- map = std::make_unique<mbgl::Map>(*frontend, mapObserver, threadpool,
+ frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio);
+ map = std::make_unique<mbgl::Map>(*frontend, mapObserver,
mbgl::MapOptions().withSize(frontend->getSize())
.withPixelRatio(pixelRatio)
.withMapMode(mode)
@@ -1214,8 +1214,8 @@ NodeMap::NodeMap(v8::Local<v8::Object> options)
: true;
}())
, mapObserver(NodeMapObserver())
- , frontend(std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size { 256, 256 }, pixelRatio, threadpool))
- , map(std::make_unique<mbgl::Map>(*frontend, mapObserver, threadpool,
+ , frontend(std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size { 256, 256 }, pixelRatio))
+ , map(std::make_unique<mbgl::Map>(*frontend, mapObserver,
mbgl::MapOptions().withSize(frontend->getSize())
.withPixelRatio(pixelRatio)
.withMapMode(mode)
diff --git a/platform/node/src/node_map.hpp b/platform/node/src/node_map.hpp
index 65664b34bb..d45dbec92b 100644
--- a/platform/node/src/node_map.hpp
+++ b/platform/node/src/node_map.hpp
@@ -1,7 +1,5 @@
#pragma once
-#include "node_thread_pool.hpp"
-
#include <mbgl/map/map.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/image.hpp>
@@ -79,7 +77,6 @@ public:
const float pixelRatio;
mbgl::MapMode mode;
bool crossSourceCollisions;
- NodeThreadPool threadpool;
NodeMapObserver mapObserver;
std::unique_ptr<mbgl::HeadlessFrontend> frontend;
std::unique_ptr<mbgl::Map> map;
diff --git a/platform/node/src/node_thread_pool.cpp b/platform/node/src/node_thread_pool.cpp
index 1f37565e8a..de403c605c 100644
--- a/platform/node/src/node_thread_pool.cpp
+++ b/platform/node/src/node_thread_pool.cpp
@@ -2,6 +2,7 @@
#include "util/async_queue.hpp"
#include <mbgl/actor/mailbox.hpp>
+#include <mbgl/platform/background_scheduler.hpp>
namespace node_mbgl {
@@ -35,3 +36,14 @@ void NodeThreadPool::Worker::WorkComplete() {
}
} // namespace node_mbgl
+
+namespace mbgl {
+namespace platform {
+
+Scheduler& GetBackgroundScheduler() {
+ static node_mbgl::NodeThreadPool pool;
+ return pool;
+}
+
+} // namespace platform
+} // namespace mbgl
diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake
index 911af25bc4..fb572b807b 100644
--- a/platform/qt/qt.cmake
+++ b/platform/qt/qt.cmake
@@ -17,12 +17,6 @@ set(MBGL_QT_CORE_FILES
PRIVATE platform/default/include/mbgl/gl/headless_backend.hpp
PRIVATE platform/qt/src/headless_backend_qt.cpp
- # Thread pool
- PRIVATE platform/default/src/mbgl/util/shared_thread_pool.cpp
- PRIVATE platform/default/include/mbgl/util/shared_thread_pool.hpp
- PRIVATE platform/default/src/mbgl/util/default_thread_pool.cpp
- PRIVATE platform/default/include/mbgl/util/default_thread_pool.hpp
-
# Thread
PRIVATE platform/qt/src/thread_local.cpp
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index e54733aba7..329bf23085 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -43,7 +43,6 @@
#include <mbgl/util/projection.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/util/traits.hpp>
#include <mbgl/actor/scheduler.hpp>
@@ -1724,7 +1723,6 @@ mbgl::ResourceOptions resourceOptionsFromQMapboxGLSettings(const QMapboxGLSettin
QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settings, const QSize &size, qreal pixelRatio_)
: QObject(q)
- , m_threadPool(mbgl::sharedThreadPool())
, m_mode(settings.contextMode())
, m_pixelRatio(pixelRatio_)
, m_localFontFamily(settings.localFontFamily())
@@ -1741,7 +1739,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
auto resourceOptions = resourceOptionsFromQMapboxGLSettings(settings);
// Setup the Map object.
- mapObj = std::make_unique<mbgl::Map>(*this, *m_mapObserver, *m_threadPool,
+ mapObj = std::make_unique<mbgl::Map>(*this, *m_mapObserver,
mapOptionsFromQMapboxGLSettings(settings, size, m_pixelRatio),
resourceOptions);
@@ -1799,7 +1797,6 @@ void QMapboxGLPrivate::createRenderer()
m_mapRenderer = std::make_unique<QMapboxGLMapRenderer>(
m_pixelRatio,
- *m_threadPool,
m_mode,
m_localFontFamily
);
diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp
index d72b5d0f2c..eba50af6bf 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.cpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.cpp
@@ -26,9 +26,9 @@ static auto *getScheduler() {
return scheduler.localData().get();
};
-QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio, mbgl::ThreadPool &tp, QMapboxGLSettings::GLContextMode mode, const QString &localFontFamily)
+QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings::GLContextMode mode, const QString &localFontFamily)
: m_backend(static_cast<mbgl::gfx::ContextMode>(mode)),
- m_renderer(std::make_unique<mbgl::Renderer>(m_backend, pixelRatio, tp, mbgl::optional<std::string> {},
+ m_renderer(std::make_unique<mbgl::Renderer>(m_backend, pixelRatio, mbgl::optional<std::string> {},
localFontFamily.isEmpty() ? mbgl::nullopt : mbgl::optional<std::string> { localFontFamily.toStdString() }))
, m_forceScheduler(needsToForceScheduler())
{
diff --git a/platform/qt/src/qmapboxgl_map_renderer.hpp b/platform/qt/src/qmapboxgl_map_renderer.hpp
index 7db0da99fa..2769b2b874 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.hpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.hpp
@@ -5,7 +5,6 @@
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/renderer/renderer_observer.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/util/util.hpp>
#include <QtGlobal>
@@ -25,7 +24,7 @@ class QMapboxGLMapRenderer : public QObject
Q_OBJECT
public:
- QMapboxGLMapRenderer(qreal pixelRatio, mbgl::ThreadPool &, QMapboxGLSettings::GLContextMode, const QString &localFontFamily);
+ QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings::GLContextMode, const QString &localFontFamily);
virtual ~QMapboxGLMapRenderer();
void render();
diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/qmapboxgl_p.hpp
index 6a5b5ce04f..7f7040d7ac 100644
--- a/platform/qt/src/qmapboxgl_p.hpp
+++ b/platform/qt/src/qmapboxgl_p.hpp
@@ -8,7 +8,6 @@
#include <mbgl/map/map.hpp>
#include <mbgl/renderer/renderer_frontend.hpp>
#include <mbgl/storage/resource_transform.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/geo.hpp>
#include <QObject>
@@ -56,7 +55,6 @@ private:
std::shared_ptr<mbgl::UpdateParameters> m_updateParameters;
std::unique_ptr<QMapboxGLMapObserver> m_mapObserver;
- std::shared_ptr<mbgl::ThreadPool> m_threadPool;
std::unique_ptr<QMapboxGLMapRenderer> m_mapRenderer;
std::unique_ptr<mbgl::Actor<mbgl::ResourceTransform>> m_resourceTransform;
diff --git a/platform/qt/src/qmapboxgl_renderer_backend.hpp b/platform/qt/src/qmapboxgl_renderer_backend.hpp
index aba8003323..f821eda969 100644
--- a/platform/qt/src/qmapboxgl_renderer_backend.hpp
+++ b/platform/qt/src/qmapboxgl_renderer_backend.hpp
@@ -4,7 +4,6 @@
#include <mbgl/gfx/renderable.hpp>
#include <mbgl/gl/renderer_backend.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
class QMapboxGLRendererBackend final : public mbgl::gl::RendererBackend,
public mbgl::gfx::Renderable {