From 817c26111a0d6650e7ebae73e46621626106d0a7 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 12 Oct 2016 17:28:22 -0400 Subject: [core] [node] pass thread pool impl to Map constructor Updates mbgl::Map constructor usage everywhere Adds NodeThreadPool implementation using AsyncQueue to call Nan::AsyncQueueWorker from main thread --- include/mbgl/map/map.hpp | 5 +++-- include/mbgl/platform/default/thread_pool.hpp | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 include/mbgl/platform/default/thread_pool.hpp (limited to 'include') diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 914c2cd0b3..2831206d54 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -19,8 +19,9 @@ namespace mbgl { -class FileSource; class View; +class FileSource; +class Scheduler; class SpriteImage; struct CameraOptions; struct AnimationOptions; @@ -32,7 +33,7 @@ class Layer; class Map : private util::noncopyable { public: - explicit Map(View&, FileSource&, + explicit Map(View&, FileSource&, Scheduler&, MapMode mapMode = MapMode::Continuous, GLContextMode contextMode = GLContextMode::Unique, ConstrainMode constrainMode = ConstrainMode::HeightOnly, diff --git a/include/mbgl/platform/default/thread_pool.hpp b/include/mbgl/platform/default/thread_pool.hpp new file mode 100644 index 0000000000..a14d16d771 --- /dev/null +++ b/include/mbgl/platform/default/thread_pool.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include +#include +#include +#include + +namespace mbgl { + +class ThreadPool : public Scheduler { +public: + ThreadPool(std::size_t count); + ~ThreadPool() override; + + void schedule(std::weak_ptr) override; + +private: + std::vector threads; + std::queue> queue; + std::mutex mutex; + std::condition_variable cv; + bool terminate { false }; +}; + +} // namespace mbgl -- cgit v1.2.1