#include #include #include #include #include #include #include #include #include #include namespace mbgl { class Worker::Impl { public: Impl(uv_loop_t*, FileSource* fs) { // FIXME: Workers should not access the FileSource but it // is currently needed because of GlyphsPBF. See #1664. util::ThreadContext::setFileSource(fs); } bool parseRasterTile(RasterBucket* bucket, std::string data) { return bucket->setImage(data); } TileParseResult parseVectorTile(TileWorker* worker, std::string data) { VectorTile vectorTile(pbf(reinterpret_cast(data.data()), data.size())); return worker->parse(vectorTile); } TileParseResult parseLiveTile(TileWorker* worker, const LiveTile* tile) { return worker->parse(*tile); } void redoPlacement(TileWorker* worker, float angle, bool collisionDebug) { worker->redoPlacement(angle, collisionDebug); } }; Worker::Worker(std::size_t count) { util::ThreadContext context = {"Worker", util::ThreadType::Worker, util::ThreadPriority::Low}; for (std::size_t i = 0; i < count; i++) { threads.emplace_back(std::make_unique>(context, util::ThreadContext::getFileSource())); } } Worker::~Worker() = default; std::unique_ptr Worker::parseRasterTile(RasterBucket& bucket, std::string data, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithResult(&Worker::Impl::parseRasterTile, callback, &bucket, data); } std::unique_ptr Worker::parseVectorTile(TileWorker& worker, std::string data, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithResult(&Worker::Impl::parseVectorTile, callback, &worker, data); } std::unique_ptr Worker::parseLiveTile(TileWorker& worker, const LiveTile& tile, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithResult(&Worker::Impl::parseLiveTile, callback, &worker, &tile); } std::unique_ptr Worker::redoPlacement(TileWorker& worker, float angle, bool collisionDebug, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithResult(&Worker::Impl::redoPlacement, callback, &worker, angle, collisionDebug); } } // end namespace mbgl