From c9a135de2cbe69ee08a1b4c67908687e8b990474 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Fri, 29 Nov 2019 14:54:52 +0200 Subject: [PATCH] [core] Retain thread pool in GeoJSONSource Otherwise, the construction of the `Immutable` in background thread might never yeld. --- include/mbgl/style/sources/geojson_source.hpp | 3 ++- src/mbgl/style/sources/geojson_source.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index 9569b61df46..df2f9d2daf2 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -14,7 +14,7 @@ namespace mbgl { class AsyncRequest; - +class Scheduler; namespace style { struct GeoJSONOptions { @@ -81,6 +81,7 @@ class GeoJSONSource final : public Source { private: optional url; std::unique_ptr req; + std::shared_ptr threadPool; mapbox::base::WeakPtrFactory weakFactory {this}; }; diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index fc8a563fd4e..ea6fb5cc68b 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -19,7 +19,7 @@ Immutable GeoJSONOptions::defaultOptions() { } GeoJSONSource::GeoJSONSource(std::string id, Immutable options) - : Source(makeMutable(std::move(id), std::move(options))) {} + : Source(makeMutable(std::move(id), std::move(options))), threadPool(Scheduler::GetBackground()) {} GeoJSONSource::~GeoJSONSource() = default; @@ -98,7 +98,7 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) { loaded = true; observer->onSourceLoaded(*this); }; - Scheduler::GetBackground()->scheduleAndReplyValue(makeImplInBackground, onImplReady); + threadPool->scheduleAndReplyValue(makeImplInBackground, onImplReady); } }); }