diff options
Diffstat (limited to 'platform/default/src')
-rw-r--r-- | platform/default/src/mbgl/gl/headless_frontend.cpp | 8 | ||||
-rw-r--r-- | platform/default/src/mbgl/map/map_snapshotter.cpp | 11 | ||||
-rw-r--r-- | platform/default/src/mbgl/platform/thread_pool.cpp (renamed from platform/default/src/mbgl/util/default_thread_pool.cpp) | 28 | ||||
-rw-r--r-- | platform/default/src/mbgl/util/shared_thread_pool.cpp | 14 |
4 files changed, 34 insertions, 27 deletions
diff --git a/platform/default/src/mbgl/gl/headless_frontend.cpp b/platform/default/src/mbgl/gl/headless_frontend.cpp index 37b0f91f32..71cd656e59 100644 --- a/platform/default/src/mbgl/gl/headless_frontend.cpp +++ b/platform/default/src/mbgl/gl/headless_frontend.cpp @@ -8,11 +8,11 @@ namespace mbgl { -HeadlessFrontend::HeadlessFrontend(float pixelRatio_, FileSource& fileSource, Scheduler& scheduler, const optional<std::string> programCacheDir, GLContextMode mode, const optional<std::string> localFontFamily) - : HeadlessFrontend({ 256, 256 }, pixelRatio_, fileSource, scheduler, programCacheDir, mode, localFontFamily) { +HeadlessFrontend::HeadlessFrontend(float pixelRatio_, FileSource& fileSource, const optional<std::string> programCacheDir, GLContextMode mode, const optional<std::string> localFontFamily) + : HeadlessFrontend({ 256, 256 }, pixelRatio_, fileSource, programCacheDir, mode, localFontFamily) { } -HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, FileSource& fileSource, Scheduler& scheduler, const optional<std::string> programCacheDir, GLContextMode mode, const optional<std::string> localFontFamily) +HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, FileSource& fileSource, const optional<std::string> programCacheDir, GLContextMode mode, const optional<std::string> localFontFamily) : size(size_), pixelRatio(pixelRatio_), backend({ static_cast<uint32_t>(size.width * pixelRatio), @@ -23,7 +23,7 @@ HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, FileSource& fi renderer->render(*updateParameters); } }), - renderer(std::make_unique<Renderer>(backend, pixelRatio, fileSource, scheduler, mode, programCacheDir, localFontFamily)) { + renderer(std::make_unique<Renderer>(backend, pixelRatio, fileSource, mode, 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 56bc9bdb88..9532b01b7e 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -15,7 +15,6 @@ namespace mbgl { class MapSnapshotter::Impl { public: Impl(FileSource*, - std::shared_ptr<Scheduler>, const std::pair<bool, std::string> style, const Size&, const float pixelRatio, @@ -42,13 +41,11 @@ public: void snapshot(ActorRef<MapSnapshotter::Callback>); private: - std::shared_ptr<Scheduler> scheduler; HeadlessFrontend frontend; Map map; }; MapSnapshotter::Impl::Impl(FileSource* fileSource, - std::shared_ptr<Scheduler> scheduler_, const std::pair<bool, std::string> style, const Size& size, const float pixelRatio, @@ -56,9 +53,8 @@ MapSnapshotter::Impl::Impl(FileSource* fileSource, const optional<LatLngBounds> region, const optional<std::string> programCacheDir, const optional<std::string> localFontFamily) - : scheduler(std::move(scheduler_)) - , frontend(size, pixelRatio, *fileSource, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily) - , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *fileSource, *scheduler, MapOptions().withMapMode(MapMode::Static)) { + , frontend(size, pixelRatio, programCacheDir, GLContextMode::Unique, localFontFamily) + , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *fileSource, MapOptions().withMapMode(MapMode::Static)) { if (style.first) { map.getStyle().loadJSON(style.second); @@ -165,7 +161,6 @@ LatLngBounds MapSnapshotter::Impl::getRegion() const { } MapSnapshotter::MapSnapshotter(FileSource* fileSource, - std::shared_ptr<Scheduler> scheduler, const std::pair<bool, std::string> style, const Size& size, const float pixelRatio, @@ -173,7 +168,7 @@ MapSnapshotter::MapSnapshotter(FileSource* fileSource, const optional<LatLngBounds> region, const optional<std::string> programCacheDir, const optional<std::string> localFontFamily) - : impl(std::make_unique<util::Thread<MapSnapshotter::Impl>>("Map Snapshotter", fileSource, std::move(scheduler), style, size, pixelRatio, cameraOptions, region, programCacheDir, localFontFamily)) { + : impl(std::make_unique<util::Thread<MapSnapshotter::Impl>>("Map Snapshotter", fileSource, style, size, pixelRatio, cameraOptions, region, programCacheDir, localFontFamily)) { } MapSnapshotter::~MapSnapshotter() = default; diff --git a/platform/default/src/mbgl/util/default_thread_pool.cpp b/platform/default/src/mbgl/platform/thread_pool.cpp index d3950bb8aa..d213aab71c 100644 --- a/platform/default/src/mbgl/util/default_thread_pool.cpp +++ b/platform/default/src/mbgl/platform/thread_pool.cpp @@ -1,12 +1,33 @@ -#include <mbgl/util/default_thread_pool.hpp> +#include <mbgl/actor/scheduler.hpp> #include <mbgl/actor/mailbox.hpp> #include <mbgl/util/platform.hpp> #include <mbgl/util/string.hpp> +#include <condition_variable> +#include <mutex> +#include <queue> +#include <thread> + namespace mbgl { +class ThreadPool final : public Scheduler { +public: + explicit ThreadPool(std::size_t count); + ~ThreadPool() override; + + void schedule(std::weak_ptr<Mailbox>) override; + +private: + std::vector<std::thread> threads; + std::queue<std::weak_ptr<Mailbox>> queue; + std::mutex mutex; + std::condition_variable cv; + bool terminate { false }; +}; + 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)); @@ -54,4 +75,9 @@ void ThreadPool::schedule(std::weak_ptr<Mailbox> mailbox) { cv.notify_one(); } +Scheduler& Scheduler::GetBackground() { + static std::unique_ptr<ThreadPool> pool(new ThreadPool(4)); + return *pool; +} + } // namespace mbgl diff --git a/platform/default/src/mbgl/util/shared_thread_pool.cpp b/platform/default/src/mbgl/util/shared_thread_pool.cpp deleted file mode 100644 index d7facbab94..0000000000 --- a/platform/default/src/mbgl/util/shared_thread_pool.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include <mbgl/util/shared_thread_pool.hpp> - -namespace mbgl { - -std::shared_ptr<ThreadPool> sharedThreadPool() { - static std::weak_ptr<ThreadPool> weak; - auto pool = weak.lock(); - if (!pool) { - weak = pool = std::make_shared<ThreadPool>(4); - } - return pool; -} - -} // namespace mbgl |