summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-01-11 12:05:19 +0100
committerKonstantin Käfer <mail@kkaefer.com>2017-01-11 12:05:19 +0100
commitbc126388f883ee299573054a31f53e248b5153c6 (patch)
tree2ac550d83278494efdbd7f97d0d225386b1d7750
parentae463564f82bd876a6ef73acfac955eb22666fc0 (diff)
downloadqtlocation-mapboxgl-bc126388f883ee299573054a31f53e248b5153c6.tar.gz
[core] add support for naming thread pool threads and setting them to low priority
adds parity with util::Thread
-rw-r--r--benchmark/api/query.benchmark.cpp2
-rw-r--r--bin/render.cpp2
-rwxr-xr-xplatform/android/src/native_map_view.cpp2
-rw-r--r--platform/default/mbgl/util/default_thread_pool.cpp10
-rw-r--r--platform/default/mbgl/util/default_thread_pool.hpp3
-rw-r--r--platform/glfw/main.cpp2
-rw-r--r--platform/ios/src/MGLMapView.mm2
-rw-r--r--platform/macos/src/MGLMapView.mm2
-rw-r--r--platform/qt/src/qmapboxgl.cpp2
-rw-r--r--test/actor/actor.test.cpp8
-rw-r--r--test/actor/actor_ref.test.cpp2
-rw-r--r--test/api/annotations.test.cpp2
-rw-r--r--test/api/api_misuse.test.cpp4
-rw-r--r--test/api/custom_layer.test.cpp2
-rw-r--r--test/api/query.test.cpp2
-rw-r--r--test/api/render_missing.test.cpp2
-rw-r--r--test/api/repeated_render.test.cpp2
-rw-r--r--test/map/map.test.cpp4
-rw-r--r--test/style/source.test.cpp2
-rw-r--r--test/tile/geojson_tile.test.cpp2
-rw-r--r--test/tile/raster_tile.test.cpp2
-rw-r--r--test/tile/vector_tile.test.cpp2
-rw-r--r--test/util/memory.test.cpp2
23 files changed, 36 insertions, 29 deletions
diff --git a/benchmark/api/query.benchmark.cpp b/benchmark/api/query.benchmark.cpp
index ba696876cd..456f43af7e 100644
--- a/benchmark/api/query.benchmark.cpp
+++ b/benchmark/api/query.benchmark.cpp
@@ -36,7 +36,7 @@ public:
HeadlessBackend backend;
OffscreenView view{ backend.getContext(), { 1000, 1000 } };
DefaultFileSource fileSource{ "benchmark/fixtures/api/cache.db", "." };
- ThreadPool threadPool{ 4 };
+ ThreadPool threadPool{ 4, { "Worker" } };
Map map{ backend, view.size, 1, fileSource, threadPool, MapMode::Still };
ScreenBox box{{ 0, 0 }, { 1000, 1000 }};
};
diff --git a/bin/render.cpp b/bin/render.cpp
index d275b445d2..0f6ff5f207 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -86,7 +86,7 @@ int main(int argc, char *argv[]) {
HeadlessBackend backend;
OffscreenView view(backend.getContext(), { width * pixelRatio, height * pixelRatio });
- ThreadPool threadPool(4);
+ ThreadPool threadPool(4, { "Worker" });
Map map(backend, mbgl::Size { width, height }, pixelRatio, fileSource, threadPool, MapMode::Still);
if (util::isURL(style_path)) {
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 8234b74af2..d2ee1a64fe 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -41,7 +41,7 @@ NativeMapView::NativeMapView(JNIEnv *env_, jobject obj_, float pixelRatio, int a
: env(env_),
availableProcessors(availableProcessors_),
totalMemory(totalMemory_),
- threadPool(4) {
+ threadPool(4, { "Worker" }) {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::NativeMapView");
assert(env_ != nullptr);
diff --git a/platform/default/mbgl/util/default_thread_pool.cpp b/platform/default/mbgl/util/default_thread_pool.cpp
index 92c0f06745..0d02c87538 100644
--- a/platform/default/mbgl/util/default_thread_pool.cpp
+++ b/platform/default/mbgl/util/default_thread_pool.cpp
@@ -1,12 +1,18 @@
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/actor/mailbox.hpp>
+#include <mbgl/util/platform.hpp>
namespace mbgl {
-ThreadPool::ThreadPool(std::size_t count) {
+ThreadPool::ThreadPool(std::size_t count, const util::ThreadContext& context) {
threads.reserve(count);
for (std::size_t i = 0; i < count; ++i) {
- threads.emplace_back([this] () {
+ threads.emplace_back([this, context] () {
+ platform::setCurrentThreadName(context.name);
+ if (context.priority == util::ThreadPriority::Low) {
+ platform::makeThreadLowPriority();
+ }
+
while (true) {
std::unique_lock<std::mutex> lock(mutex);
diff --git a/platform/default/mbgl/util/default_thread_pool.hpp b/platform/default/mbgl/util/default_thread_pool.hpp
index a14d16d771..f86da5b50c 100644
--- a/platform/default/mbgl/util/default_thread_pool.hpp
+++ b/platform/default/mbgl/util/default_thread_pool.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/actor/scheduler.hpp>
+#include <mbgl/util/thread_context.hpp>
#include <condition_variable>
#include <mutex>
@@ -11,7 +12,7 @@ namespace mbgl {
class ThreadPool : public Scheduler {
public:
- ThreadPool(std::size_t count);
+ ThreadPool(std::size_t count, const util::ThreadContext&);
~ThreadPool() override;
void schedule(std::weak_ptr<Mailbox>) override;
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 1f683b185f..f9b1ec93cc 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -118,7 +118,7 @@ int main(int argc, char *argv[]) {
fileSource.setAccessToken(std::string(token));
}
- mbgl::ThreadPool threadPool(4);
+ mbgl::ThreadPool threadPool(4, { "Worker" });
mbgl::Map map(backend, view->getSize(), view->getPixelRatio(), fileSource, threadPool);
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 608acf016d..4866dd5783 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -421,7 +421,7 @@ public:
// setup mbgl map
mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
const float scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale];
- _mbglThreadPool = new mbgl::ThreadPool(4);
+ _mbglThreadPool = new mbgl::ThreadPool(4, { "Worker" });
_mbglMap = new mbgl::Map(*_mbglView, self.size, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
[self validateTileCacheSize];
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 92aa0a6c6b..5df5a1f957 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -259,7 +259,7 @@ public:
mbgl::DefaultFileSource* mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
- _mbglThreadPool = new mbgl::ThreadPool(4);
+ _mbglThreadPool = new mbgl::ThreadPool(4, { "Worker" });
_mbglMap = new mbgl::Map(*_mbglView, self.size, [NSScreen mainScreen].backingScaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default);
[self validateTileCacheSize];
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 86604a945f..9d3b5dc099 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -1498,7 +1498,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
settings.cacheDatabasePath().toStdString(),
settings.assetPath().toStdString(),
settings.cacheDatabaseMaximumSize()))
- , threadPool(4)
+ , threadPool(4, { "Worker" })
, mapObj(std::make_unique<mbgl::Map>(
*this, mbgl::Size{ static_cast<uint32_t>(size.width()), static_cast<uint32_t>(size.height()) },
pixelRatio, *fileSourceObj, threadPool,
diff --git a/test/actor/actor.test.cpp b/test/actor/actor.test.cpp
index 03f41a6e64..ad8d91f6b5 100644
--- a/test/actor/actor.test.cpp
+++ b/test/actor/actor.test.cpp
@@ -19,7 +19,7 @@ TEST(Actor, Construction) {
};
};
- ThreadPool pool { 1 };
+ ThreadPool pool { 1, { "ActorConstruction" } };
bool constructed = false;
Actor<Test> test(pool, std::ref(constructed));
@@ -52,7 +52,7 @@ TEST(Actor, DestructionClosesMailbox) {
}
};
- ThreadPool pool { 1 };
+ ThreadPool pool { 1, { "ActorDestructionClosesMailbox" } };
std::promise<void> enteredPromise;
std::future<void> enteredFuture = enteredPromise.get_future();
@@ -88,7 +88,7 @@ TEST(Actor, OrderedMailbox) {
}
};
- ThreadPool pool { 1 };
+ ThreadPool pool { 1, { "ActorOrderedMailbox" } };
std::promise<void> endedPromise;
std::future<void> endedFuture = endedPromise.get_future();
@@ -124,7 +124,7 @@ TEST(Actor, NonConcurrentMailbox) {
}
};
- ThreadPool pool { 10 };
+ ThreadPool pool { 10, { "ActorNonConcurrentMailbox" } };
std::promise<void> endedPromise;
std::future<void> endedFuture = endedPromise.get_future();
diff --git a/test/actor/actor_ref.test.cpp b/test/actor/actor_ref.test.cpp
index 78721c965e..8877e3aaf8 100644
--- a/test/actor/actor_ref.test.cpp
+++ b/test/actor/actor_ref.test.cpp
@@ -30,7 +30,7 @@ TEST(ActorRef, CanOutliveActor) {
}
};
- ThreadPool pool { 1 };
+ ThreadPool pool { 1, { "ActorRefCanOutliveActor" } };
bool died = false;
ActorRef<Test> test = [&] () {
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index 72a2d62bde..6e5351a91d 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -26,7 +26,7 @@ public:
HeadlessBackend backend { test::sharedDisplay() };
OffscreenView view { backend.getContext() };
StubFileSource fileSource;
- ThreadPool threadPool { 4 };
+ ThreadPool threadPool { 4, { "Worker" } };
Map map { backend, view.size, 1, fileSource, threadPool, MapMode::Still };
void checkRendering(const char * name) {
diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp
index 34272f5366..5ecba8be5d 100644
--- a/test/api/api_misuse.test.cpp
+++ b/test/api/api_misuse.test.cpp
@@ -24,7 +24,7 @@ TEST(API, RenderWithoutCallback) {
HeadlessBackend backend { test::sharedDisplay() };
OffscreenView view { backend.getContext(), { 128, 512 } };
StubFileSource fileSource;
- ThreadPool threadPool(4);
+ ThreadPool threadPool{ 4, { "Worker" } };
std::unique_ptr<Map> map =
std::make_unique<Map>(backend, view.size, 1, fileSource, threadPool, MapMode::Still);
@@ -49,7 +49,7 @@ TEST(API, RenderWithoutStyle) {
HeadlessBackend backend { test::sharedDisplay() };
OffscreenView view { backend.getContext(), { 128, 512 } };
StubFileSource fileSource;
- ThreadPool threadPool(4);
+ ThreadPool threadPool{ 4, { "Worker" } };
Map map(backend, view.size, 1, fileSource, threadPool, MapMode::Still);
diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp
index 73b4e94af5..227523d90a 100644
--- a/test/api/custom_layer.test.cpp
+++ b/test/api/custom_layer.test.cpp
@@ -95,7 +95,7 @@ TEST(CustomLayer, Basic) {
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
#endif
- ThreadPool threadPool(4);
+ ThreadPool threadPool{ 4, { "Worker" } };
Map map(backend, view.size, 1, fileSource, threadPool, MapMode::Still);
map.setStyleJSON(util::read_file("test/fixtures/api/water.json"));
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index 86687fc818..964ae7caea 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -29,7 +29,7 @@ public:
HeadlessBackend backend { test::sharedDisplay() };
OffscreenView view { backend.getContext() };
StubFileSource fileSource;
- ThreadPool threadPool { 4 };
+ ThreadPool threadPool { 4, { "Worker" } };
Map map { backend, view.size, 1, fileSource, threadPool, MapMode::Still };
};
diff --git a/test/api/render_missing.test.cpp b/test/api/render_missing.test.cpp
index a5c59913bc..9c53f35102 100644
--- a/test/api/render_missing.test.cpp
+++ b/test/api/render_missing.test.cpp
@@ -34,7 +34,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
#endif
- ThreadPool threadPool(4);
+ ThreadPool threadPool{ 4, { "Worker" } };
Log::setObserver(std::make_unique<FixtureLogObserver>());
diff --git a/test/api/repeated_render.test.cpp b/test/api/repeated_render.test.cpp
index 49b9a31b0b..4ece3c3150 100644
--- a/test/api/repeated_render.test.cpp
+++ b/test/api/repeated_render.test.cpp
@@ -30,7 +30,7 @@ TEST(API, RepeatedRender) {
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
#endif
- ThreadPool threadPool(4);
+ ThreadPool threadPool{ 4, { "Worker" } };
Log::setObserver(std::make_unique<FixtureLogObserver>());
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 8eedeb3c01..9ee2d45a81 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -26,7 +26,7 @@ struct MapTest {
HeadlessBackend backend { test::sharedDisplay() };
OffscreenView view { backend.getContext() };
StubFileSource fileSource;
- ThreadPool threadPool { 4 };
+ ThreadPool threadPool{ 4, { "Worker" } };
};
TEST(Map, LatLngBehavior) {
@@ -475,7 +475,7 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
util::RunLoop runLoop;
MockBackend backend { test::sharedDisplay() };
OffscreenView view { backend.getContext() };
- ThreadPool threadPool { 4 };
+ ThreadPool threadPool{ 4, { "Worker" } };
#ifdef MBGL_ASSET_ZIP
// Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/`
diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp
index 01f54d6b18..69fb5c368c 100644
--- a/test/style/source.test.cpp
+++ b/test/style/source.test.cpp
@@ -31,7 +31,7 @@ public:
StubStyleObserver observer;
Transform transform;
TransformState transformState;
- ThreadPool threadPool { 1 };
+ ThreadPool threadPool{ 1, { "Worker" } };
AnnotationManager annotationManager { 1.0 };
style::Style style { fileSource, 1.0 };
diff --git a/test/tile/geojson_tile.test.cpp b/test/tile/geojson_tile.test.cpp
index 920e946a2b..dbebbe5707 100644
--- a/test/tile/geojson_tile.test.cpp
+++ b/test/tile/geojson_tile.test.cpp
@@ -22,7 +22,7 @@ public:
FakeFileSource fileSource;
TransformState transformState;
util::RunLoop loop;
- ThreadPool threadPool { 1 };
+ ThreadPool threadPool{ 1, { "Worker" } };
AnnotationManager annotationManager { 1.0 };
style::Style style { fileSource, 1.0 };
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
diff --git a/test/tile/raster_tile.test.cpp b/test/tile/raster_tile.test.cpp
index 0d599ceae0..5181d7052f 100644
--- a/test/tile/raster_tile.test.cpp
+++ b/test/tile/raster_tile.test.cpp
@@ -17,7 +17,7 @@ public:
FakeFileSource fileSource;
TransformState transformState;
util::RunLoop loop;
- ThreadPool threadPool { 1 };
+ ThreadPool threadPool{ 1, { "Worker" } };
AnnotationManager annotationManager { 1.0 };
style::Style style { fileSource, 1.0 };
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp
index e34629bdba..909a088794 100644
--- a/test/tile/vector_tile.test.cpp
+++ b/test/tile/vector_tile.test.cpp
@@ -23,7 +23,7 @@ public:
FakeFileSource fileSource;
TransformState transformState;
util::RunLoop loop;
- ThreadPool threadPool { 1 };
+ ThreadPool threadPool{ 1, { "Worker" } };
AnnotationManager annotationManager { 1.0 };
style::Style style { fileSource, 1.0 };
Tileset tileset { { "https://example.com" }, { 0, 22 }, "none" };
diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp
index 984e7a3e24..fdade220e6 100644
--- a/test/util/memory.test.cpp
+++ b/test/util/memory.test.cpp
@@ -59,7 +59,7 @@ public:
HeadlessBackend backend { test::sharedDisplay() };
OffscreenView view{ backend.getContext(), { 512, 512 } };
StubFileSource fileSource;
- ThreadPool threadPool { 4 };
+ ThreadPool threadPool{ 4, { "Worker" } };
private:
Response response(const std::string& path) {