summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmark/api/query.benchmark.cpp6
-rw-r--r--benchmark/api/render.benchmark.cpp18
-rw-r--r--bin/render.cpp6
-rw-r--r--include/mbgl/actor/actor.hpp5
-rw-r--r--include/mbgl/actor/scheduler.hpp5
-rw-r--r--include/mbgl/map/map.hpp2
-rw-r--r--include/mbgl/renderer/renderer.hpp3
-rw-r--r--include/mbgl/style/style.hpp3
-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/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/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
-rw-r--r--src/core-files.json2
-rw-r--r--src/mbgl/actor/scheduler.cpp20
-rw-r--r--src/mbgl/map/map.cpp4
-rw-r--r--src/mbgl/map/map_impl.cpp4
-rw-r--r--src/mbgl/map/map_impl.hpp5
-rw-r--r--src/mbgl/renderer/renderer.cpp2
-rw-r--r--src/mbgl/renderer/renderer_impl.cpp3
-rw-r--r--src/mbgl/renderer/renderer_impl.hpp3
-rw-r--r--src/mbgl/renderer/tile_parameters.hpp2
-rw-r--r--src/mbgl/sprite/sprite_loader.cpp8
-rw-r--r--src/mbgl/sprite/sprite_loader.hpp3
-rw-r--r--src/mbgl/style/sources/custom_geometry_source.cpp4
-rw-r--r--src/mbgl/style/style.cpp4
-rw-r--r--src/mbgl/style/style_impl.cpp7
-rw-r--r--src/mbgl/style/style_impl.hpp4
-rw-r--r--src/mbgl/tile/geometry_tile.cpp3
-rw-r--r--src/mbgl/tile/raster_dem_tile.cpp3
-rw-r--r--src/mbgl/tile/raster_tile.cpp3
-rw-r--r--src/mbgl/util/thread_pool.cpp (renamed from platform/default/src/mbgl/util/default_thread_pool.cpp)5
-rw-r--r--src/mbgl/util/thread_pool.hpp (renamed from platform/default/include/mbgl/util/default_thread_pool.hpp)7
-rw-r--r--test/actor/actor.test.cpp85
-rw-r--r--test/actor/actor_ref.test.cpp14
-rw-r--r--test/api/annotations.test.cpp6
-rw-r--r--test/api/api_misuse.test.cpp6
-rw-r--r--test/api/custom_geometry_source.test.cpp6
-rw-r--r--test/api/custom_layer.test.cpp6
-rw-r--r--test/api/query.test.cpp6
-rw-r--r--test/api/recycle_map.cpp7
-rw-r--r--test/gl/context.test.cpp7
-rw-r--r--test/map/map.test.cpp15
-rw-r--r--test/map/prefetch.test.cpp6
-rw-r--r--test/renderer/image_manager.test.cpp1
-rw-r--r--test/sprite/sprite_loader.test.cpp4
-rw-r--r--test/src/mbgl/test/map_adapter.hpp3
-rw-r--r--test/src/mbgl/test/test.cpp1
-rw-r--r--test/style/source.test.cpp6
-rw-r--r--test/style/style.test.cpp10
-rw-r--r--test/style/style_layer.test.cpp4
-rw-r--r--test/text/local_glyph_rasterizer.test.cpp6
-rw-r--r--test/tile/custom_geometry_tile.test.cpp5
-rw-r--r--test/tile/geojson_tile.test.cpp5
-rw-r--r--test/tile/raster_dem_tile.test.cpp5
-rw-r--r--test/tile/raster_tile.test.cpp5
-rw-r--r--test/tile/vector_tile.test.cpp5
-rw-r--r--test/util/async_task.test.cpp19
-rw-r--r--test/util/memory.test.cpp14
-rw-r--r--test/util/thread.test.cpp11
84 files changed, 218 insertions, 375 deletions
diff --git a/benchmark/api/query.benchmark.cpp b/benchmark/api/query.benchmark.cpp
index 9b7c2d7273..7f08da73d0 100644
--- a/benchmark/api/query.benchmark.cpp
+++ b/benchmark/api/query.benchmark.cpp
@@ -3,7 +3,6 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
@@ -30,9 +29,8 @@ public:
}
util::RunLoop loop;
- ThreadPool threadPool{ 4 };
- HeadlessFrontend frontend { { 1000, 1000 }, 1, threadPool };
- Map map { frontend, MapObserver::nullObserver(), threadPool,
+ HeadlessFrontend frontend { { 1000, 1000 }, 1 };
+ Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()),
ResourceOptions().withCachePath("benchmark/fixtures/api/cache.db").withAssetPath(".").withAccessToken("foobar") };
ScreenBox box{{ 0, 0 }, { 1000, 1000 }};
diff --git a/benchmark/api/render.benchmark.cpp b/benchmark/api/render.benchmark.cpp
index 3cff0d9056..f9d3911f0b 100644
--- a/benchmark/api/render.benchmark.cpp
+++ b/benchmark/api/render.benchmark.cpp
@@ -4,7 +4,6 @@
#include <mbgl/map/map_observer.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
@@ -29,7 +28,6 @@ public:
}
util::RunLoop loop;
- ThreadPool threadPool { 4 };
};
static void prepare(Map& map, optional<std::string> json = {}) {
@@ -44,8 +42,8 @@ static void prepare(Map& map, optional<std::string> json = {}) {
static void API_renderStill_reuse_map(::benchmark::State& state) {
RenderBenchmark bench;
- HeadlessFrontend frontend { size, pixelRatio, bench.threadPool };
- Map map { frontend, MapObserver::nullObserver(), bench.threadPool,
+ HeadlessFrontend frontend { size, pixelRatio };
+ Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") };
prepare(map);
@@ -57,8 +55,8 @@ static void API_renderStill_reuse_map(::benchmark::State& state) {
static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state) {
RenderBenchmark bench;
- HeadlessFrontend frontend { size, pixelRatio, bench.threadPool };
- Map map { frontend, MapObserver::nullObserver(), bench.threadPool,
+ HeadlessFrontend frontend { size, pixelRatio };
+ Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") };
prepare(map, util::read_file("benchmark/fixtures/api/style_formatted_labels.json"));
@@ -70,8 +68,8 @@ static void API_renderStill_reuse_map_formatted_labels(::benchmark::State& state
static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) {
RenderBenchmark bench;
- HeadlessFrontend frontend { size, pixelRatio, bench.threadPool };
- Map map { frontend, MapObserver::nullObserver(), bench.threadPool,
+ HeadlessFrontend frontend { size, pixelRatio };
+ Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") };
@@ -87,8 +85,8 @@ static void API_renderStill_recreate_map(::benchmark::State& state) {
RenderBenchmark bench;
while (state.KeepRunning()) {
- HeadlessFrontend frontend { size, pixelRatio, bench.threadPool };
- Map map { frontend, MapObserver::nullObserver(), bench.threadPool,
+ HeadlessFrontend frontend { size, pixelRatio };
+ Map map { frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cachePath).withAccessToken("foobar") };
prepare(map);
diff --git a/bin/render.cpp b/bin/render.cpp
index a805953693..48402ffce6 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -5,7 +5,6 @@
#include <mbgl/util/default_styles.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/style/style.hpp>
#include <args.hxx>
@@ -76,9 +75,8 @@ int main(int argc, char *argv[]) {
util::RunLoop loop;
- ThreadPool threadPool(4);
- HeadlessFrontend frontend({ width, height }, pixelRatio, threadPool);
- Map map(frontend, MapObserver::nullObserver(), threadPool,
+ HeadlessFrontend frontend({ width, height }, pixelRatio);
+ Map map(frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()).withPixelRatio(pixelRatio),
ResourceOptions().withCachePath(cache_file).withAssetPath(asset_root).withAccessToken(std::string(token)));
diff --git a/include/mbgl/actor/actor.hpp b/include/mbgl/actor/actor.hpp
index 0052fad242..97964ae531 100644
--- a/include/mbgl/actor/actor.hpp
+++ b/include/mbgl/actor/actor.hpp
@@ -55,6 +55,10 @@ public:
Actor(Scheduler& scheduler, Args&&... args)
: target(scheduler, parent, std::forward<Args>(args)...) {}
+ template <class... Args>
+ Actor(std::shared_ptr<Scheduler> scheduler, Args&&... args)
+ : retainer(std::move(scheduler)), target(*retainer, parent, std::forward<Args>(args)...) {}
+
Actor(const Actor&) = delete;
ActorRef<std::decay_t<Object>> self() {
@@ -62,6 +66,7 @@ public:
}
private:
+ std::shared_ptr<Scheduler> retainer;
AspiringActor<Object> parent;
EstablishedActor<Object> target;
};
diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp
index 75ead29f0a..6470ab1245 100644
--- a/include/mbgl/actor/scheduler.hpp
+++ b/include/mbgl/actor/scheduler.hpp
@@ -41,6 +41,11 @@ public:
// Set/Get the current Scheduler for this thread
static Scheduler* GetCurrent();
static void SetCurrent(Scheduler*);
+
+ // Get the scheduler for asynchronous tasks. This method
+ // will lazily initialize a shared worker pool when ran
+ // from the first time.
+ static std::shared_ptr<Scheduler> GetBackground();
};
} // namespace mbgl
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 2fdd72dcb8..b1d4b14e4f 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -22,7 +22,6 @@
namespace mbgl {
-class Scheduler;
class RendererFrontend;
namespace style {
@@ -34,7 +33,6 @@ class Map : private util::noncopyable {
public:
explicit Map(RendererFrontend&,
MapObserver&,
- Scheduler&,
const MapOptions&,
const ResourceOptions&);
~Map();
diff --git a/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp
index 50483fcf4b..787f9dceee 100644
--- a/include/mbgl/renderer/renderer.hpp
+++ b/include/mbgl/renderer/renderer.hpp
@@ -14,7 +14,6 @@ namespace mbgl {
class RendererObserver;
class RenderedQueryOptions;
-class Scheduler;
class SourceQueryOptions;
class UpdateParameters;
@@ -24,7 +23,7 @@ class RendererBackend;
class Renderer {
public:
- Renderer(gfx::RendererBackend&, float pixelRatio_, Scheduler&,
+ Renderer(gfx::RendererBackend&, float pixelRatio_,
const optional<std::string> programCacheDir = {},
const optional<std::string> localFontFamily = {});
~Renderer();
diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp
index d6fdbd8f2c..4a6a542b88 100644
--- a/include/mbgl/style/style.hpp
+++ b/include/mbgl/style/style.hpp
@@ -11,7 +11,6 @@
namespace mbgl {
class FileSource;
-class Scheduler;
namespace style {
@@ -22,7 +21,7 @@ class Layer;
class Style {
public:
- Style(Scheduler&, FileSource&, float pixelRatio);
+ Style(FileSource&, float pixelRatio);
~Style();
void loadJSON(const std::string&);
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/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/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 {
diff --git a/src/core-files.json b/src/core-files.json
index c0412dd3a8..d721935268 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -302,6 +302,7 @@
"src/mbgl/util/rapidjson.cpp",
"src/mbgl/util/stopwatch.cpp",
"src/mbgl/util/string.cpp",
+ "src/mbgl/util/thread_pool.cpp",
"src/mbgl/util/tile_cover.cpp",
"src/mbgl/util/tile_cover_impl.cpp",
"src/mbgl/util/tiny_sdf.cpp",
@@ -762,6 +763,7 @@
"mbgl/util/std.hpp": "src/mbgl/util/std.hpp",
"mbgl/util/stopwatch.hpp": "src/mbgl/util/stopwatch.hpp",
"mbgl/util/thread_local.hpp": "src/mbgl/util/thread_local.hpp",
+ "mbgl/util/thread_pool.hpp": "src/mbgl/util/thread_pool.hpp",
"mbgl/util/tile_coordinate.hpp": "src/mbgl/util/tile_coordinate.hpp",
"mbgl/util/tile_cover.hpp": "src/mbgl/util/tile_cover.hpp",
"mbgl/util/tile_cover_impl.hpp": "src/mbgl/util/tile_cover_impl.hpp",
diff --git a/src/mbgl/actor/scheduler.cpp b/src/mbgl/actor/scheduler.cpp
index d7cdb2737b..cb0c7728ec 100644
--- a/src/mbgl/actor/scheduler.cpp
+++ b/src/mbgl/actor/scheduler.cpp
@@ -1,8 +1,11 @@
#include <mbgl/actor/scheduler.hpp>
#include <mbgl/util/thread_local.hpp>
+#include <mbgl/util/thread_pool.hpp>
namespace mbgl {
-
+
+util::ThreadLocal<Scheduler> g_currentScheduler;
+
static auto& current() {
static util::ThreadLocal<Scheduler> scheduler;
return scheduler;
@@ -16,4 +19,19 @@ Scheduler* Scheduler::GetCurrent() {
return current().get();
}
+// static
+std::shared_ptr<Scheduler> Scheduler::GetBackground() {
+ static std::weak_ptr<Scheduler> weak;
+ static std::mutex mtx;
+
+ std::lock_guard<std::mutex> lock(mtx);
+ std::shared_ptr<Scheduler> scheduler = weak.lock();
+
+ if (!scheduler) {
+ weak = scheduler = std::make_shared<ThreadPool>(4);
+ }
+
+ return scheduler;
+}
+
} //namespace mbgl
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index c31bb8ca34..c35f33305c 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -17,7 +17,6 @@
#include <mbgl/util/exception.hpp>
#include <mbgl/util/mapbox.hpp>
#include <mbgl/util/tile_coordinate.hpp>
-#include <mbgl/actor/scheduler.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/math/log2.hpp>
@@ -29,10 +28,9 @@ using namespace style;
Map::Map(RendererFrontend& frontend,
MapObserver& observer,
- Scheduler& scheduler,
const MapOptions& mapOptions,
const ResourceOptions& resourceOptions)
- : impl(std::make_unique<Impl>(frontend, observer, scheduler,
+ : impl(std::make_unique<Impl>(frontend, observer,
FileSource::getSharedFileSource(resourceOptions),
mapOptions)) {}
diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp
index 1ec7255822..fa15461ff2 100644
--- a/src/mbgl/map/map_impl.cpp
+++ b/src/mbgl/map/map_impl.cpp
@@ -9,18 +9,16 @@ namespace mbgl {
Map::Impl::Impl(RendererFrontend& frontend_,
MapObserver& observer_,
- Scheduler& scheduler_,
std::shared_ptr<FileSource> fileSource_,
const MapOptions& mapOptions)
: observer(observer_),
rendererFrontend(frontend_),
- scheduler(scheduler_),
transform(observer, mapOptions.constrainMode(), mapOptions.viewportMode()),
mode(mapOptions.mapMode()),
pixelRatio(mapOptions.pixelRatio()),
crossSourceCollisions(mapOptions.crossSourceCollisions()),
fileSource(std::move(fileSource_)),
- style(std::make_unique<style::Style>(scheduler, *fileSource, pixelRatio)),
+ style(std::make_unique<style::Style>(*fileSource, pixelRatio)),
annotationManager(*style) {
transform.setNorthOrientation(mapOptions.northOrientation());
style->impl->setObserver(this);
diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp
index f233f78275..84b43c8343 100644
--- a/src/mbgl/map/map_impl.hpp
+++ b/src/mbgl/map/map_impl.hpp
@@ -1,7 +1,5 @@
#pragma once
-#include <mbgl/actor/actor.hpp>
-#include <mbgl/actor/scheduler.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_observer.hpp>
@@ -30,7 +28,7 @@ struct StillImageRequest {
class Map::Impl : public style::Observer, public RendererObserver {
public:
- Impl(RendererFrontend&, MapObserver&, Scheduler&, std::shared_ptr<FileSource>, const MapOptions&);
+ Impl(RendererFrontend&, MapObserver&, std::shared_ptr<FileSource>, const MapOptions&);
~Impl() final;
// StyleObserver
@@ -54,7 +52,6 @@ public:
MapObserver& observer;
RendererFrontend& rendererFrontend;
- Scheduler& scheduler;
Transform transform;
diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp
index 18cb0ebc07..ba213c435d 100644
--- a/src/mbgl/renderer/renderer.cpp
+++ b/src/mbgl/renderer/renderer.cpp
@@ -9,12 +9,10 @@ namespace mbgl {
Renderer::Renderer(gfx::RendererBackend& backend,
float pixelRatio_,
- Scheduler& scheduler_,
const optional<std::string> programCacheDir_,
const optional<std::string> localFontFamily_)
: impl(std::make_unique<Impl>(backend,
pixelRatio_,
- scheduler_,
std::move(programCacheDir_),
std::move(localFontFamily_))) {
}
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp
index c756234e8d..3db9439b5c 100644
--- a/src/mbgl/renderer/renderer_impl.cpp
+++ b/src/mbgl/renderer/renderer_impl.cpp
@@ -40,11 +40,9 @@ static RendererObserver& nullObserver() {
Renderer::Impl::Impl(gfx::RendererBackend& backend_,
float pixelRatio_,
- Scheduler& scheduler_,
const optional<std::string> programCacheDir_,
const optional<std::string> localFontFamily_)
: backend(backend_)
- , scheduler(scheduler_)
, observer(&nullObserver())
, pixelRatio(pixelRatio_)
, programCacheDir(std::move(programCacheDir_))
@@ -114,7 +112,6 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
updateParameters.pixelRatio,
updateParameters.debugOptions,
updateParameters.transformState,
- scheduler,
updateParameters.fileSource,
updateParameters.mode,
updateParameters.annotationManager,
diff --git a/src/mbgl/renderer/renderer_impl.hpp b/src/mbgl/renderer/renderer_impl.hpp
index f0d4720ce2..270ea4d517 100644
--- a/src/mbgl/renderer/renderer_impl.hpp
+++ b/src/mbgl/renderer/renderer_impl.hpp
@@ -26,7 +26,6 @@ class UpdateParameters;
class RenderStaticData;
class RenderedQueryOptions;
class SourceQueryOptions;
-class Scheduler;
class GlyphManager;
class ImageManager;
class LineAtlas;
@@ -42,7 +41,6 @@ class Renderer::Impl : public GlyphManagerObserver,
public:
Impl(gfx::RendererBackend&,
float pixelRatio_,
- Scheduler&,
const optional<std::string> programCacheDir,
const optional<std::string> localFontFamily_);
~Impl() final;
@@ -99,7 +97,6 @@ private:
friend class Renderer;
gfx::RendererBackend& backend;
- Scheduler& scheduler;
RendererObserver* observer;
diff --git a/src/mbgl/renderer/tile_parameters.hpp b/src/mbgl/renderer/tile_parameters.hpp
index 665c7490d2..cbe8dfb3ba 100644
--- a/src/mbgl/renderer/tile_parameters.hpp
+++ b/src/mbgl/renderer/tile_parameters.hpp
@@ -5,7 +5,6 @@
namespace mbgl {
class TransformState;
-class Scheduler;
class FileSource;
class AnnotationManager;
class ImageManager;
@@ -16,7 +15,6 @@ public:
const float pixelRatio;
const MapDebugOptions debugOptions;
const TransformState& transformState;
- Scheduler& workerScheduler;
FileSource& fileSource;
const MapMode mode;
AnnotationManager& annotationManager;
diff --git a/src/mbgl/sprite/sprite_loader.cpp b/src/mbgl/sprite/sprite_loader.cpp
index ce8fbe5894..bfb0c570d6 100644
--- a/src/mbgl/sprite/sprite_loader.cpp
+++ b/src/mbgl/sprite/sprite_loader.cpp
@@ -20,9 +20,9 @@ namespace mbgl {
static SpriteLoaderObserver nullObserver;
struct SpriteLoader::Loader {
- Loader(Scheduler& scheduler, SpriteLoader& imageManager)
+ Loader(SpriteLoader& imageManager)
: mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
- worker(scheduler, ActorRef<SpriteLoader>(imageManager, mailbox)) {
+ worker(Scheduler::GetBackground(), ActorRef<SpriteLoader>(imageManager, mailbox)) {
}
std::shared_ptr<const std::string> image;
@@ -40,14 +40,14 @@ SpriteLoader::SpriteLoader(float pixelRatio_)
SpriteLoader::~SpriteLoader() = default;
-void SpriteLoader::load(const std::string& url, Scheduler& scheduler, FileSource& fileSource) {
+void SpriteLoader::load(const std::string& url, FileSource& fileSource) {
if (url.empty()) {
// Treat a non-existent sprite as a successfully loaded empty sprite.
observer->onSpriteLoaded({});
return;
}
- loader = std::make_unique<Loader>(scheduler, *this);
+ loader = std::make_unique<Loader>(*this);
loader->jsonRequest = fileSource.request(Resource::spriteJSON(url, pixelRatio), [this](Response res) {
if (res.error) {
diff --git a/src/mbgl/sprite/sprite_loader.hpp b/src/mbgl/sprite/sprite_loader.hpp
index 0daf46be9c..0b7d37fa14 100644
--- a/src/mbgl/sprite/sprite_loader.hpp
+++ b/src/mbgl/sprite/sprite_loader.hpp
@@ -12,7 +12,6 @@
namespace mbgl {
-class Scheduler;
class FileSource;
class SpriteLoaderObserver;
@@ -21,7 +20,7 @@ public:
SpriteLoader(float pixelRatio);
~SpriteLoader();
- void load(const std::string& url, Scheduler&, FileSource&);
+ void load(const std::string& url, FileSource&);
void setObserver(SpriteLoaderObserver*);
diff --git a/src/mbgl/style/sources/custom_geometry_source.cpp b/src/mbgl/style/sources/custom_geometry_source.cpp
index 7420be9320..6e9d8d65fb 100644
--- a/src/mbgl/style/sources/custom_geometry_source.cpp
+++ b/src/mbgl/style/sources/custom_geometry_source.cpp
@@ -4,7 +4,6 @@
#include <mbgl/actor/actor.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <mbgl/tile/tile_id.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <tuple>
#include <map>
@@ -14,8 +13,7 @@ namespace style {
CustomGeometrySource::CustomGeometrySource(std::string id,
const CustomGeometrySource::Options options)
: Source(makeMutable<CustomGeometrySource::Impl>(std::move(id), options)),
- threadPool(sharedThreadPool()),
- loader(std::make_unique<Actor<CustomTileLoader>>(*threadPool, options.fetchTileFunction, options.cancelTileFunction)) {
+ loader(std::make_unique<Actor<CustomTileLoader>>(Scheduler::GetBackground(), options.fetchTileFunction, options.cancelTileFunction)) {
}
CustomGeometrySource::~CustomGeometrySource() = default;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index bd8631fc52..783c850097 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -8,8 +8,8 @@
namespace mbgl {
namespace style {
-Style::Style(Scheduler& scheduler, FileSource& fileSource, float pixelRatio)
- : impl(std::make_unique<Impl>(scheduler, fileSource, pixelRatio)) {
+Style::Style(FileSource& fileSource, float pixelRatio)
+ : impl(std::make_unique<Impl>(fileSource, pixelRatio)) {
}
Style::~Style() = default;
diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp
index d527b8440b..10fee73cdd 100644
--- a/src/mbgl/style/style_impl.cpp
+++ b/src/mbgl/style/style_impl.cpp
@@ -27,9 +27,8 @@ namespace style {
static Observer nullObserver;
-Style::Impl::Impl(Scheduler& scheduler_, FileSource& fileSource_, float pixelRatio)
- : scheduler(scheduler_),
- fileSource(fileSource_),
+Style::Impl::Impl(FileSource& fileSource_, float pixelRatio)
+ : fileSource(fileSource_),
spriteLoader(std::make_unique<SpriteLoader>(pixelRatio)),
light(std::make_unique<Light>()),
observer(&nullObserver) {
@@ -111,7 +110,7 @@ void Style::Impl::parse(const std::string& json_) {
setLight(std::make_unique<Light>(parser.light));
spriteLoaded = false;
- spriteLoader->load(parser.spriteURL, scheduler, fileSource);
+ spriteLoader->load(parser.spriteURL, fileSource);
glyphURL = parser.glyphURL;
loaded = true;
diff --git a/src/mbgl/style/style_impl.hpp b/src/mbgl/style/style_impl.hpp
index 3dc222bfad..4c56f6785b 100644
--- a/src/mbgl/style/style_impl.hpp
+++ b/src/mbgl/style/style_impl.hpp
@@ -25,7 +25,6 @@
namespace mbgl {
-class Scheduler;
class FileSource;
class AsyncRequest;
class SpriteLoader;
@@ -38,7 +37,7 @@ class Style::Impl : public SpriteLoaderObserver,
public LightObserver,
public util::noncopyable {
public:
- Impl(Scheduler&, FileSource&, float pixelRatio);
+ Impl(FileSource&, float pixelRatio);
~Impl() override;
void loadJSON(const std::string&);
@@ -98,7 +97,6 @@ public:
private:
void parse(const std::string&);
- Scheduler& scheduler;
FileSource& fileSource;
std::string url;
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index 029c761e53..d110b2f826 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -1,4 +1,5 @@
#include <mbgl/tile/geometry_tile.hpp>
+
#include <mbgl/tile/geometry_tile_worker.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/tile/tile_observer.hpp>
@@ -45,7 +46,7 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_,
ImageRequestor(parameters.imageManager),
sourceID(std::move(sourceID_)),
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
- worker(parameters.workerScheduler,
+ worker(Scheduler::GetBackground(),
ActorRef<GeometryTile>(*this, mailbox),
id_,
sourceID,
diff --git a/src/mbgl/tile/raster_dem_tile.cpp b/src/mbgl/tile/raster_dem_tile.cpp
index 224c5c9062..8b4e0113c7 100644
--- a/src/mbgl/tile/raster_dem_tile.cpp
+++ b/src/mbgl/tile/raster_dem_tile.cpp
@@ -1,4 +1,5 @@
#include <mbgl/tile/raster_dem_tile.hpp>
+
#include <mbgl/tile/raster_dem_tile_worker.hpp>
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/tile/tile_loader_impl.hpp>
@@ -17,7 +18,7 @@ RasterDEMTile::RasterDEMTile(const OverscaledTileID& id_,
: Tile(Kind::RasterDEM, id_),
loader(*this, id_, parameters, tileset),
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
- worker(parameters.workerScheduler,
+ worker(Scheduler::GetBackground(),
ActorRef<RasterDEMTile>(*this, mailbox)) {
encoding = tileset.encoding;
diff --git a/src/mbgl/tile/raster_tile.cpp b/src/mbgl/tile/raster_tile.cpp
index ff02301021..9da11b3595 100644
--- a/src/mbgl/tile/raster_tile.cpp
+++ b/src/mbgl/tile/raster_tile.cpp
@@ -1,4 +1,5 @@
#include <mbgl/tile/raster_tile.hpp>
+
#include <mbgl/tile/raster_tile_worker.hpp>
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/tile/tile_loader_impl.hpp>
@@ -17,7 +18,7 @@ RasterTile::RasterTile(const OverscaledTileID& id_,
: Tile(Kind::Raster, id_),
loader(*this, id_, parameters, tileset),
mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
- worker(parameters.workerScheduler,
+ worker(Scheduler::GetBackground(),
ActorRef<RasterTile>(*this, mailbox)) {
}
diff --git a/platform/default/src/mbgl/util/default_thread_pool.cpp b/src/mbgl/util/thread_pool.cpp
index d3950bb8aa..79c2f75012 100644
--- a/platform/default/src/mbgl/util/default_thread_pool.cpp
+++ b/src/mbgl/util/thread_pool.cpp
@@ -1,5 +1,5 @@
-#include <mbgl/util/default_thread_pool.hpp>
-#include <mbgl/actor/mailbox.hpp>
+#include <mbgl/util/thread_pool.hpp>
+
#include <mbgl/util/platform.hpp>
#include <mbgl/util/string.hpp>
@@ -7,6 +7,7 @@ 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));
diff --git a/platform/default/include/mbgl/util/default_thread_pool.hpp b/src/mbgl/util/thread_pool.hpp
index a14d16d771..509fd06061 100644
--- a/platform/default/include/mbgl/util/default_thread_pool.hpp
+++ b/src/mbgl/util/thread_pool.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <mbgl/actor/mailbox.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <condition_variable>
@@ -9,9 +10,9 @@
namespace mbgl {
-class ThreadPool : public Scheduler {
+class ThreadPool final : public Scheduler {
public:
- ThreadPool(std::size_t count);
+ explicit ThreadPool(std::size_t count);
~ThreadPool() override;
void schedule(std::weak_ptr<Mailbox>) override;
@@ -21,7 +22,7 @@ private:
std::queue<std::weak_ptr<Mailbox>> queue;
std::mutex mutex;
std::condition_variable cv;
- bool terminate { false };
+ bool terminate{ false };
};
} // namespace mbgl
diff --git a/test/actor/actor.test.cpp b/test/actor/actor.test.cpp
index 02308b7ce0..6db95a83f1 100644
--- a/test/actor/actor.test.cpp
+++ b/test/actor/actor.test.cpp
@@ -1,8 +1,8 @@
#include <mbgl/actor/actor.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
-#include <mbgl/util/run_loop.hpp>
+#include <mbgl/actor/scheduler.hpp>
#include <mbgl/test/util.hpp>
+#include <mbgl/util/run_loop.hpp>
#include <chrono>
#include <functional>
@@ -20,9 +20,8 @@ TEST(Actor, Construction) {
};
};
- ThreadPool pool { 1 };
bool constructed = false;
- Actor<Test> test(pool, std::ref(constructed));
+ Actor<Test> test(Scheduler::GetBackground(), std::ref(constructed));
EXPECT_TRUE(constructed);
}
@@ -33,14 +32,13 @@ TEST(Actor, Destruction) {
~Test() {
destructed = true;
}
-
+
bool& destructed;
};
- ThreadPool pool { 1 };
bool destructed = false;
{
- Actor<Test> test(pool, std::ref(destructed));
+ Actor<Test> test(Scheduler::GetBackground(), std::ref(destructed));
}
EXPECT_TRUE(destructed);
@@ -72,15 +70,13 @@ TEST(Actor, DestructionBlocksOnReceive) {
}
};
- ThreadPool pool { 1 };
-
std::promise<void> enteredPromise;
std::future<void> enteredFuture = enteredPromise.get_future();
std::promise<void> exitingPromise;
std::future<void> exitingFuture = exitingPromise.get_future();
- Actor<Test> test(pool, std::move(enteredPromise), std::move(exitingFuture));
+ Actor<Test> test(Scheduler::GetBackground(), std::move(enteredPromise), std::move(exitingFuture));
test.self().invoke(&Test::wait);
enteredFuture.wait();
@@ -157,11 +153,9 @@ TEST(Actor, DestructionAllowedInReceiveOnSameThread) {
}
};
- ThreadPool pool { 1 };
-
std::promise<void> callbackFiredPromise;
-
- auto test = std::make_unique<Actor<Test>>(pool);
+ auto retainer = Scheduler::GetBackground();
+ auto test = std::make_unique<Actor<Test>>(retainer);
// Callback (triggered while mutex is locked in Mailbox::receive())
test->self().invoke(&Test::callMeBack, [&]() {
@@ -189,12 +183,10 @@ TEST(Actor, SelfDestructionDoesntCrashWaitingReceivingThreads) {
};
- ThreadPool pool { 2 };
-
std::promise<void> actorClosedPromise;
- auto closingActor = std::make_unique<Actor<Test>>(pool);
- auto waitingActor = std::make_unique<Actor<Test>>(pool);
+ auto closingActor = std::make_unique<Actor<Test>>(Scheduler::GetBackground());
+ auto waitingActor = std::make_unique<Actor<Test>>(Scheduler::GetBackground());
std::atomic<bool> waitingMessageProcessed {false};
@@ -251,11 +243,9 @@ TEST(Actor, OrderedMailbox) {
}
};
- ThreadPool pool { 1 };
-
std::promise<void> endedPromise;
std::future<void> endedFuture = endedPromise.get_future();
- Actor<Test> test(pool, std::move(endedPromise));
+ Actor<Test> test(Scheduler::GetBackground(), std::move(endedPromise));
for (auto i = 1; i <= 10; ++i) {
test.self().invoke(&Test::receive, i);
@@ -287,11 +277,9 @@ TEST(Actor, NonConcurrentMailbox) {
}
};
- ThreadPool pool { 10 };
-
std::promise<void> endedPromise;
std::future<void> endedFuture = endedPromise.get_future();
- Actor<Test> test(pool, std::move(endedPromise));
+ Actor<Test> test(Scheduler::GetBackground(), std::move(endedPromise));
for (auto i = 1; i <= 10; ++i) {
test.self().invoke(&Test::receive, i);
@@ -313,13 +301,12 @@ TEST(Actor, Ask) {
}
};
- ThreadPool pool { 2 };
- Actor<Test> test(pool);
+ Actor<Test> test(Scheduler::GetBackground());
auto result = test.self().ask(&Test::doubleIt, 1);
ASSERT_TRUE(result.valid());
-
+
auto status = result.wait_for(std::chrono::seconds(1));
ASSERT_EQ(std::future_status::ready, status);
ASSERT_EQ(2, result.get());
@@ -339,9 +326,8 @@ TEST(Actor, AskVoid) {
}
};
- ThreadPool pool { 1 };
bool executed = false;
- Actor<Test> actor(pool, executed);
+ Actor<Test> actor(Scheduler::GetBackground(), executed);
actor.self().ask(&Test::doIt).get();
EXPECT_TRUE(executed);
@@ -349,31 +335,30 @@ TEST(Actor, AskVoid) {
TEST(Actor, NoSelfActorRef) {
// Not all actors need a reference to self
-
+
// Trivially constructable
struct Trivial {};
-
- ThreadPool pool { 2 };
- Actor<Trivial> trivial(pool);
-
-
+
+ Actor<Trivial> trivial(Scheduler::GetBackground());
+
+
// With arguments
struct WithArguments {
std::promise<void> promise;
-
+
WithArguments(std::promise<void> promise_)
: promise(std::move(promise_)) {
}
-
+
void receive() {
promise.set_value();
}
};
-
+
std::promise<void> promise;
auto future = promise.get_future();
- Actor<WithArguments> withArguments(pool, std::move(promise));
-
+ Actor<WithArguments> withArguments(Scheduler::GetBackground(), std::move(promise));
+
withArguments.self().invoke(&WithArguments::receive);
future.wait();
}
@@ -386,32 +371,32 @@ TEST(Actor, TwoPhaseConstruction) {
struct Test {
Test(ActorRef<Test>, std::shared_ptr<bool> destroyed_)
: destroyed(std::move(destroyed_)) {};
-
+
~Test() {
*destroyed = true;
}
-
+
void callMe(std::promise<void> p) {
p.set_value();
}
-
+
void stop() {
util::RunLoop::Get()->stop();
}
-
+
std::shared_ptr<bool> destroyed;
};
AspiringActor<Test> parent;
-
+
auto destroyed = std::make_shared<bool>(false);
-
+
std::promise<void> queueExecuted;
auto queueExecutedFuture = queueExecuted.get_future();
-
+
parent.self().invoke(&Test::callMe, std::move(queueExecuted));
parent.self().invoke(&Test::stop);
-
+
auto thread = std::thread([
capturedArgs = std::make_tuple(destroyed),
&parent
@@ -420,11 +405,11 @@ TEST(Actor, TwoPhaseConstruction) {
EstablishedActor<Test> test(loop, parent, capturedArgs);
loop.run();
});
-
+
// should not hang
queueExecutedFuture.get();
thread.join();
-
+
EXPECT_TRUE(*destroyed);
}
diff --git a/test/actor/actor_ref.test.cpp b/test/actor/actor_ref.test.cpp
index 20aa1c35c1..221a220ed9 100644
--- a/test/actor/actor_ref.test.cpp
+++ b/test/actor/actor_ref.test.cpp
@@ -1,6 +1,6 @@
#include <mbgl/actor/actor.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
+#include <mbgl/actor/scheduler.hpp>
#include <mbgl/test/util.hpp>
#include <future>
@@ -27,11 +27,10 @@ TEST(ActorRef, CanOutliveActor) {
}
};
- ThreadPool pool { 1 };
bool died = false;
ActorRef<Test> test = [&] () {
- return Actor<Test>(pool, std::ref(died)).self();
+ return Actor<Test>(Scheduler::GetBackground(), std::ref(died)).self();
}();
EXPECT_TRUE(died);
@@ -54,8 +53,7 @@ TEST(ActorRef, Ask) {
}
};
- ThreadPool pool { 1 };
- Actor<Test> actor(pool);
+ Actor<Test> actor(Scheduler::GetBackground());
ActorRef<Test> ref = actor.self();
EXPECT_EQ(20, ref.ask(&Test::gimme).get());
@@ -76,9 +74,8 @@ TEST(ActorRef, AskVoid) {
}
};
- ThreadPool pool { 1 };
bool executed = false;
- Actor<Test> actor(pool, executed);
+ Actor<Test> actor(Scheduler::GetBackground(), executed);
ActorRef<Test> ref = actor.self();
ref.ask(&Test::doIt).get();
@@ -104,8 +101,7 @@ TEST(ActorRef, AskOnDestroyedActor) {
};
bool died = false;
- ThreadPool pool { 1 };
- auto actor = std::make_unique<Actor<Test>>(pool, died);
+ auto actor = std::make_unique<Actor<Test>>(Scheduler::GetBackground(), died);
ActorRef<Test> ref = actor->self();
actor.reset();
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index 11920d1624..2d76a3d154 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -2,7 +2,6 @@
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/map_adapter.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
@@ -28,10 +27,9 @@ std::unique_ptr<style::Image> namedMarker(const std::string& name) {
class AnnotationTest {
public:
util::RunLoop loop;
- ThreadPool threadPool { 4 };
- HeadlessFrontend frontend { 1, threadPool };
+ HeadlessFrontend frontend { 1 };
- MapAdapter map { frontend, MapObserver::nullObserver(), std::make_shared<StubFileSource>(), threadPool,
+ MapAdapter map { frontend, MapObserver::nullObserver(), std::make_shared<StubFileSource>(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())};
void checkRendering(const char * name) {
diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp
index b65bdf9918..54d8eb5912 100644
--- a/test/api/api_misuse.test.cpp
+++ b/test/api/api_misuse.test.cpp
@@ -6,7 +6,6 @@
#include <mbgl/map/map_options.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -21,11 +20,10 @@ TEST(API, RenderWithoutCallback) {
util::RunLoop loop;
- ThreadPool threadPool(4);
- HeadlessFrontend frontend { 1, threadPool };
+ HeadlessFrontend frontend { 1 };
auto map = std::make_unique<MapAdapter>(frontend, MapObserver::nullObserver(),
- std::make_shared<StubFileSource>(), threadPool,
+ std::make_shared<StubFileSource>(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()));
map->renderStill(nullptr);
diff --git a/test/api/custom_geometry_source.test.cpp b/test/api/custom_geometry_source.test.cpp
index f796e3086b..df65dc2703 100644
--- a/test/api/custom_geometry_source.test.cpp
+++ b/test/api/custom_geometry_source.test.cpp
@@ -2,7 +2,6 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/style/style.hpp>
@@ -20,9 +19,8 @@ using namespace mbgl::style;
TEST(CustomGeometrySource, Grid) {
util::RunLoop loop;
- auto threadPool = sharedThreadPool();
- HeadlessFrontend frontend { 1, *threadPool };
- Map map(frontend, MapObserver::nullObserver(), *threadPool,
+ HeadlessFrontend frontend { 1 };
+ Map map(frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()),
ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets"));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp
index 4a0a34bafc..e9b9aee9bc 100644
--- a/test/api/custom_layer.test.cpp
+++ b/test/api/custom_layer.test.cpp
@@ -3,7 +3,6 @@
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/storage/resource_options.hpp>
@@ -90,9 +89,8 @@ public:
TEST(CustomLayer, Basic) {
util::RunLoop loop;
- ThreadPool threadPool(4);
- HeadlessFrontend frontend { 1, threadPool };
- Map map(frontend, MapObserver::nullObserver(), threadPool,
+ HeadlessFrontend frontend { 1 };
+ Map map(frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()),
ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets"));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index ddf5df6aab..b80d3b7d8a 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -1,7 +1,6 @@
#include <mbgl/test/map_adapter.hpp>
#include <mbgl/map/map_options.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/util.hpp>
#include <mbgl/util/image.hpp>
@@ -35,9 +34,8 @@ public:
util::RunLoop loop;
std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
- ThreadPool threadPool { 4 };
- HeadlessFrontend frontend { 1, threadPool };
- MapAdapter map { frontend, MapObserver::nullObserver(), fileSource, threadPool,
+ HeadlessFrontend frontend { 1 };
+ MapAdapter map { frontend, MapObserver::nullObserver(), fileSource,
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())};
};
diff --git a/test/api/recycle_map.cpp b/test/api/recycle_map.cpp
index 18cc9c00aa..55e19e3cd9 100644
--- a/test/api/recycle_map.cpp
+++ b/test/api/recycle_map.cpp
@@ -9,7 +9,6 @@
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/style/image.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/geojson.hpp>
@@ -23,11 +22,9 @@ using namespace mbgl::style;
TEST(API, RecycleMapUpdateImages) {
util::RunLoop loop;
- ThreadPool threadPool(4);
-
- HeadlessFrontend frontend { 1, threadPool };
+ HeadlessFrontend frontend { 1 };
auto map = std::make_unique<MapAdapter>(frontend, MapObserver::nullObserver(),
- std::make_shared<StubFileSource>(), threadPool,
+ std::make_shared<StubFileSource>(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()));
EXPECT_TRUE(map);
diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp
index b8fe895c44..756f2c58d4 100644
--- a/test/gl/context.test.cpp
+++ b/test/gl/context.test.cpp
@@ -4,7 +4,6 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_options.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/headless_frontend.hpp>
@@ -88,11 +87,9 @@ struct Buffer {
TEST(GLContextMode, Shared) {
util::RunLoop loop;
- ThreadPool threadPool(4);
+ HeadlessFrontend frontend { 1, {}, gfx::ContextMode::Shared };
- HeadlessFrontend frontend { 1, threadPool, {}, gfx::ContextMode::Shared };
-
- Map map(frontend, MapObserver::nullObserver(), threadPool,
+ Map map(frontend, MapObserver::nullObserver(),
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()),
ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets"));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 3af2acdb8b..ee86ce7f77 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -9,7 +9,6 @@
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/storage/default_file_source.hpp>
@@ -34,15 +33,14 @@ class MapTest {
public:
util::RunLoop runLoop;
std::shared_ptr<FileSource> fileSource;
- ThreadPool threadPool { 4 };
StubMapObserver observer;
HeadlessFrontend frontend;
MapAdapter map;
MapTest(float pixelRatio = 1, MapMode mode = MapMode::Static)
: fileSource(std::make_shared<FileSource>())
- , frontend(pixelRatio, threadPool)
- , map(frontend, observer, fileSource, threadPool,
+ , frontend(pixelRatio)
+ , map(frontend, observer, fileSource,
MapOptions().withMapMode(mode).withSize(frontend.getSize()).withPixelRatio(pixelRatio)) {}
template <typename T = FileSource>
@@ -50,8 +48,8 @@ public:
float pixelRatio = 1, MapMode mode = MapMode::Static,
typename std::enable_if<std::is_same<T, DefaultFileSource>::value>::type* = nullptr)
: fileSource(std::make_shared<T>(cachePath, assetPath))
- , frontend(pixelRatio, threadPool)
- , map(frontend, observer, fileSource, threadPool,
+ , frontend(pixelRatio)
+ , map(frontend, observer, fileSource,
MapOptions().withMapMode(mode).withSize(frontend.getSize()).withPixelRatio(pixelRatio)) {}
};
@@ -744,7 +742,6 @@ TEST(Map, DontLoadUnneededTiles) {
TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
util::RunLoop runLoop;
- ThreadPool threadPool { 4 };
using namespace std::chrono_literals;
@@ -756,7 +753,7 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
util::Timer timer;
- HeadlessFrontend frontend(1, threadPool);
+ HeadlessFrontend frontend(1);
StubMapObserver observer;
observer.didFinishRenderingFrameCallback = [&] (MapObserver::RenderMode) {
@@ -768,7 +765,7 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
});
};
- Map map(frontend, observer, threadPool,
+ Map map(frontend, observer,
MapOptions().withMapMode(MapMode::Continuous).withSize(frontend.getSize()),
ResourceOptions().withCachePath(":memory:").withAssetPath("test/fixtures/api/assets"));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp
index 3232c99a22..071c918427 100644
--- a/test/map/prefetch.test.cpp
+++ b/test/map/prefetch.test.cpp
@@ -6,7 +6,6 @@
#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
@@ -22,7 +21,6 @@ using namespace std::chrono_literals;
TEST(Map, PrefetchTiles) {
util::RunLoop runLoop;
- ThreadPool threadPool(4);
std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
util::Timer emergencyShutoff;
@@ -36,8 +34,8 @@ TEST(Map, PrefetchTiles) {
runLoop.stop();
};
- HeadlessFrontend frontend { { 512, 512 }, 1, threadPool };
- MapAdapter map(frontend, observer, fileSource, threadPool,
+ HeadlessFrontend frontend { { 512, 512 }, 1 };
+ MapAdapter map(frontend, observer, fileSource,
MapOptions().withMapMode(MapMode::Continuous).withSize(frontend.getSize()));
std::vector<int> tiles;
diff --git a/test/renderer/image_manager.test.cpp b/test/renderer/image_manager.test.cpp
index 7f0d670846..87a24e3bd3 100644
--- a/test/renderer/image_manager.test.cpp
+++ b/test/renderer/image_manager.test.cpp
@@ -9,7 +9,6 @@
#include <mbgl/util/io.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/string.hpp>
#include <utility>
diff --git a/test/sprite/sprite_loader.test.cpp b/test/sprite/sprite_loader.test.cpp
index 3691572265..122e711f51 100644
--- a/test/sprite/sprite_loader.test.cpp
+++ b/test/sprite/sprite_loader.test.cpp
@@ -8,7 +8,6 @@
#include <mbgl/util/io.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/string.hpp>
#include <utility>
@@ -37,7 +36,6 @@ public:
util::RunLoop loop;
StubFileSource fileSource;
StubSpriteLoaderObserver observer;
- ThreadPool threadPool { 1 };
SpriteLoader spriteLoader{ 1 };
void run() {
@@ -45,7 +43,7 @@ public:
Log::setObserver(std::make_unique<Log::NullObserver>());
spriteLoader.setObserver(&observer);
- spriteLoader.load("test/fixtures/resources/sprite", threadPool, fileSource);
+ spriteLoader.load("test/fixtures/resources/sprite", fileSource);
loop.run();
}
diff --git a/test/src/mbgl/test/map_adapter.hpp b/test/src/mbgl/test/map_adapter.hpp
index 5bdab1d164..d4af579ae1 100644
--- a/test/src/mbgl/test/map_adapter.hpp
+++ b/test/src/mbgl/test/map_adapter.hpp
@@ -13,9 +13,8 @@ public:
explicit MapAdapter(RendererFrontend& frontend,
MapObserver& observer,
std::shared_ptr<FileSource> fileSource,
- Scheduler& scheduler,
const MapOptions& options)
- : Map(std::make_unique<Map::Impl>(frontend, observer, scheduler, std::move(fileSource), options)) {}
+ : Map(std::make_unique<Map::Impl>(frontend, observer, std::move(fileSource), options)) {}
};
} // namespace mbgl
diff --git a/test/src/mbgl/test/test.cpp b/test/src/mbgl/test/test.cpp
index 4c3dad1727..1c77aae2a1 100644
--- a/test/src/mbgl/test/test.cpp
+++ b/test/src/mbgl/test/test.cpp
@@ -1,3 +1,4 @@
+#include <mbgl/actor/scheduler.hpp>
#include <mbgl/test.hpp>
#include <mbgl/test/util.hpp>
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp
index f0ff1f81b4..289e41c75f 100644
--- a/test/style/source.test.cpp
+++ b/test/style/source.test.cpp
@@ -31,7 +31,6 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/tileset.hpp>
-#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/range.hpp>
@@ -55,8 +54,7 @@ public:
StubRenderSourceObserver renderSourceObserver;
Transform transform;
TransformState transformState;
- ThreadPool threadPool { 1 };
- Style style { loop, fileSource, 1 };
+ Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
@@ -65,7 +63,6 @@ public:
1.0,
MapDebugOptions(),
transformState,
- threadPool,
fileSource,
MapMode::Continuous,
annotationManager,
@@ -763,7 +760,6 @@ TEST(Source, ImageSourceImageUpdate) {
TEST(Source, CustomGeometrySourceSetTileData) {
SourceTest test;
- std::shared_ptr<ThreadPool> threadPool = sharedThreadPool();
CustomGeometrySource source("source", CustomGeometrySource::Options());
source.loadDescription(test.fileSource);
diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp
index 7f57651331..72f74d3b01 100644
--- a/test/style/style.test.cpp
+++ b/test/style/style.test.cpp
@@ -9,7 +9,6 @@
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <memory>
@@ -19,9 +18,8 @@ using namespace mbgl::style;
TEST(Style, Properties) {
util::RunLoop loop;
- ThreadPool threadPool{ 1 };
StubFileSource fileSource;
- Style::Impl style { threadPool, fileSource, 1.0 };
+ Style::Impl style { fileSource, 1.0 };
style.loadJSON(R"STYLE({"name": "Test"})STYLE");
ASSERT_EQ("Test", style.getName());
@@ -62,9 +60,8 @@ TEST(Style, Properties) {
TEST(Style, DuplicateSource) {
util::RunLoop loop;
- ThreadPool threadPool{ 1 };
StubFileSource fileSource;
- Style::Impl style { threadPool, fileSource, 1.0 };
+ Style::Impl style { fileSource, 1.0 };
style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
@@ -84,9 +81,8 @@ TEST(Style, RemoveSourceInUse) {
auto log = new FixtureLogObserver();
Log::setObserver(std::unique_ptr<Log::Observer>(log));
- ThreadPool threadPool{ 1 };
StubFileSource fileSource;
- Style::Impl style { threadPool, fileSource, 1.0 };
+ Style::Impl style { fileSource, 1.0 };
style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp
index 7598d888e9..d6a926c631 100644
--- a/test/style/style_layer.test.cpp
+++ b/test/style/style_layer.test.cpp
@@ -21,7 +21,6 @@
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/io.hpp>
#include <memory>
@@ -283,9 +282,8 @@ TEST(Layer, DuplicateLayer) {
util::RunLoop loop;
// Setup style
- ThreadPool threadPool{ 1 };
StubFileSource fileSource;
- Style::Impl style { threadPool, fileSource, 1.0 };
+ Style::Impl style { fileSource, 1.0 };
style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
// Add initial layer
diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp
index f21ac0b883..4c0719e16c 100644
--- a/test/text/local_glyph_rasterizer.test.cpp
+++ b/test/text/local_glyph_rasterizer.test.cpp
@@ -8,7 +8,6 @@
#include <mbgl/util/color.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/style/style.hpp>
/*
@@ -34,15 +33,14 @@ namespace {
class LocalGlyphRasterizerTest {
public:
LocalGlyphRasterizerTest(const optional<std::string> fontFamily)
- : frontend(1, threadPool, optional<std::string>(), gfx::ContextMode::Unique, fontFamily)
+ : frontend(1, optional<std::string>(), gfx::ContextMode::Unique, fontFamily)
{
}
util::RunLoop loop;
std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
- ThreadPool threadPool { 4 };
HeadlessFrontend frontend;
- MapAdapter map { frontend, MapObserver::nullObserver(), fileSource, threadPool,
+ MapAdapter map { frontend, MapObserver::nullObserver(), fileSource,
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())};
void checkRendering(const char * name) {
diff --git a/test/tile/custom_geometry_tile.test.cpp b/test/tile/custom_geometry_tile.test.cpp
index 7a627bad88..50bc7d0e8f 100644
--- a/test/tile/custom_geometry_tile.test.cpp
+++ b/test/tile/custom_geometry_tile.test.cpp
@@ -5,7 +5,6 @@
#include <mbgl/tile/custom_geometry_tile.hpp>
#include <mbgl/style/custom_tile_loader.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
@@ -26,8 +25,7 @@ public:
FakeFileSource fileSource;
TransformState transformState;
util::RunLoop loop;
- ThreadPool threadPool { 1 };
- style::Style style { loop, fileSource, 1 };
+ style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
@@ -36,7 +34,6 @@ public:
1.0,
MapDebugOptions(),
transformState,
- threadPool,
fileSource,
MapMode::Continuous,
annotationManager,
diff --git a/test/tile/geojson_tile.test.cpp b/test/tile/geojson_tile.test.cpp
index 772590efb2..4f4435182f 100644
--- a/test/tile/geojson_tile.test.cpp
+++ b/test/tile/geojson_tile.test.cpp
@@ -4,7 +4,6 @@
#include <mbgl/tile/geojson_tile.hpp>
#include <mbgl/tile/tile_loader_impl.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
@@ -25,8 +24,7 @@ public:
FakeFileSource fileSource;
TransformState transformState;
util::RunLoop loop;
- ThreadPool threadPool { 1 };
- style::Style style { loop, fileSource, 1 };
+ style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
@@ -36,7 +34,6 @@ public:
1.0,
MapDebugOptions(),
transformState,
- threadPool,
fileSource,
MapMode::Continuous,
annotationManager,
diff --git a/test/tile/raster_dem_tile.test.cpp b/test/tile/raster_dem_tile.test.cpp
index 5a6f5a8c9a..e2e7d44b9b 100644
--- a/test/tile/raster_dem_tile.test.cpp
+++ b/test/tile/raster_dem_tile.test.cpp
@@ -4,7 +4,6 @@
#include <mbgl/tile/tile_loader_impl.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
@@ -20,8 +19,7 @@ public:
FakeFileSource fileSource;
TransformState transformState;
util::RunLoop loop;
- ThreadPool threadPool { 1 };
- style::Style style { loop, fileSource, 1 };
+ style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
@@ -31,7 +29,6 @@ public:
1.0,
MapDebugOptions(),
transformState,
- threadPool,
fileSource,
MapMode::Continuous,
annotationManager,
diff --git a/test/tile/raster_tile.test.cpp b/test/tile/raster_tile.test.cpp
index 8b2b3dee61..2e35a94025 100644
--- a/test/tile/raster_tile.test.cpp
+++ b/test/tile/raster_tile.test.cpp
@@ -4,7 +4,6 @@
#include <mbgl/tile/tile_loader_impl.hpp>
#include <mbgl/style/style.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
@@ -20,8 +19,7 @@ public:
FakeFileSource fileSource;
TransformState transformState;
util::RunLoop loop;
- ThreadPool threadPool { 1 };
- style::Style style { loop, fileSource, 1 };
+ style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
@@ -31,7 +29,6 @@ public:
1.0,
MapDebugOptions(),
transformState,
- threadPool,
fileSource,
MapMode::Continuous,
annotationManager,
diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp
index ed3eda7863..c610d8c1a7 100644
--- a/test/tile/vector_tile.test.cpp
+++ b/test/tile/vector_tile.test.cpp
@@ -4,7 +4,6 @@
#include <mbgl/tile/vector_tile_data.hpp>
#include <mbgl/tile/tile_loader_impl.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/style/style.hpp>
@@ -26,8 +25,7 @@ public:
FakeFileSource fileSource;
TransformState transformState;
util::RunLoop loop;
- ThreadPool threadPool { 1 };
- style::Style style { loop, fileSource, 1 };
+ style::Style style { fileSource, 1 };
AnnotationManager annotationManager { style };
ImageManager imageManager;
GlyphManager glyphManager { fileSource };
@@ -37,7 +35,6 @@ public:
1.0,
MapDebugOptions(),
transformState,
- threadPool,
fileSource,
MapMode::Continuous,
annotationManager,
diff --git a/test/util/async_task.test.cpp b/test/util/async_task.test.cpp
index f3025e8952..682926a17d 100644
--- a/test/util/async_task.test.cpp
+++ b/test/util/async_task.test.cpp
@@ -1,14 +1,15 @@
#include <mbgl/util/async_task.hpp>
-#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
-#include <mbgl/actor/actor_ref.hpp>
+#include <mbgl/actor/actor_ref.hpp>
+#include <mbgl/actor/scheduler.hpp>
#include <mbgl/test/util.hpp>
+#include <mbgl/util/run_loop.hpp>
#include <atomic>
#include <future>
#include <vector>
+using namespace mbgl;
using namespace mbgl::util;
namespace {
@@ -104,11 +105,11 @@ TEST(AsyncTask, RequestCoalescingMultithreaded) {
unsigned count = 0, numThreads = 25;
AsyncTask async([&count] { ++count; });
- mbgl::ThreadPool threads(numThreads);
- auto mailbox = std::make_shared<mbgl::Mailbox>(threads);
+ auto retainer = Scheduler::GetBackground();
+ auto mailbox = std::make_shared<Mailbox>(*retainer);
TestWorker worker(&async);
- mbgl::ActorRef<TestWorker> workerRef(worker, mailbox);
+ ActorRef<TestWorker> workerRef(worker, mailbox);
for (unsigned i = 0; i < numThreads; ++i) {
workerRef.invoke(&TestWorker::run);
@@ -133,11 +134,11 @@ TEST(AsyncTask, ThreadSafety) {
AsyncTask async([&count] { ++count; });
- mbgl::ThreadPool threads(numThreads);
- auto mailbox = std::make_shared<mbgl::Mailbox>(threads);
+ auto retainer = Scheduler::GetBackground();
+ auto mailbox = std::make_shared<Mailbox>(*retainer);
TestWorker worker(&async);
- mbgl::ActorRef<TestWorker> workerRef(worker, mailbox);
+ ActorRef<TestWorker> workerRef(worker, mailbox);
for (unsigned i = 0; i < numThreads; ++i) {
// The callback runs on the worker, thus the atomic type.
diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp
index e3ad976432..8602e6ac5b 100644
--- a/test/util/memory.test.cpp
+++ b/test/util/memory.test.cpp
@@ -5,7 +5,6 @@
#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/style/style.hpp>
@@ -37,7 +36,6 @@ public:
util::RunLoop runLoop;
std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
- ThreadPool threadPool { 4 };
private:
Response response(const std::string& path) {
@@ -72,8 +70,8 @@ TEST(Memory, Vector) {
MemoryTest test;
float ratio { 2 };
- HeadlessFrontend frontend { { 256, 256 }, ratio, test.threadPool };
- MapAdapter map(frontend, MapObserver::nullObserver(), test.fileSource, test.threadPool,
+ HeadlessFrontend frontend { { 256, 256 }, ratio };
+ MapAdapter map(frontend, MapObserver::nullObserver(), test.fileSource,
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()).withPixelRatio(ratio));
map.jumpTo(CameraOptions().withZoom(16));
map.getStyle().loadURL("mapbox://streets");
@@ -85,8 +83,8 @@ TEST(Memory, Raster) {
MemoryTest test;
float ratio { 2 };
- HeadlessFrontend frontend { { 256, 256 }, ratio, test.threadPool };
- MapAdapter map(frontend, MapObserver::nullObserver(), test.fileSource, test.threadPool,
+ HeadlessFrontend frontend { { 256, 256 }, ratio };
+ MapAdapter map(frontend, MapObserver::nullObserver(), test.fileSource,
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()).withPixelRatio(ratio));
map.getStyle().loadURL("mapbox://satellite");
@@ -123,8 +121,8 @@ TEST(Memory, Footprint) {
class FrontendAndMap {
public:
FrontendAndMap(MemoryTest& test_, const char* style)
- : frontend(Size{ 256, 256 }, 2, test_.threadPool)
- , map(frontend, MapObserver::nullObserver(), test_.fileSource, test_.threadPool,
+ : frontend(Size{ 256, 256 }, 2)
+ , map(frontend, MapObserver::nullObserver(), test_.fileSource,
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()).withPixelRatio(2)) {
map.jumpTo(CameraOptions().withZoom(16));
map.getStyle().loadURL(style);
diff --git a/test/util/thread.test.cpp b/test/util/thread.test.cpp
index 2bcb9d8959..49735585c6 100644
--- a/test/util/thread.test.cpp
+++ b/test/util/thread.test.cpp
@@ -1,8 +1,9 @@
+#include <mbgl/util/thread.hpp>
+
#include <mbgl/actor/actor_ref.hpp>
+#include <mbgl/actor/scheduler.hpp>
#include <mbgl/test/util.hpp>
-#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/run_loop.hpp>
-#include <mbgl/util/thread.hpp>
#include <mbgl/util/timer.hpp>
#include <atomic>
@@ -139,8 +140,7 @@ TEST(Thread, Concurrency) {
unsigned numMessages = 100000;
std::atomic_uint completed(numMessages);
- ThreadPool threadPool(10);
- Actor<TestWorker> poolWorker(threadPool);
+ Actor<TestWorker> poolWorker(Scheduler::GetBackground());
auto poolWorkerRef = poolWorker.self();
Thread<TestWorker> threadedObject("Test");
@@ -165,8 +165,7 @@ TEST(Thread, Concurrency) {
TEST(Thread, ThreadPoolMessaging) {
auto loop = std::make_shared<RunLoop>();
- ThreadPool threadPool(1);
- Actor<TestWorker> poolWorker(threadPool);
+ Actor<TestWorker> poolWorker(Scheduler::GetBackground());
auto poolWorkerRef = poolWorker.self();
Thread<TestWorker> threadedObject("Test");