#include #include #include #include #include #include #include #include #include namespace mbgl { class Worker::Impl { public: Impl() = default; void parseRasterTile(std::unique_ptr bucket, const std::shared_ptr data, std::function callback) { try { bucket->setImage(decodeImage(*data)); callback(RasterTileParseResult(std::move(bucket))); } catch (...) { callback(std::current_exception()); } } void parseGeometryTile(TileWorker* worker, std::vector> layers, std::unique_ptr tile, PlacementConfig config, std::function callback) { try { callback(worker->parseAllLayers(std::move(layers), *tile, config)); } catch (...) { callback(std::current_exception()); } } void parsePendingGeometryTileLayers(TileWorker* worker, std::function callback) { try { callback(worker->parsePendingLayers()); } catch (...) { callback(std::current_exception()); } } void redoPlacement(TileWorker* worker, const std::unordered_map>* buckets, PlacementConfig config, std::function callback) { worker->redoPlacement(buckets, config); callback(); } }; 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)); } } Worker::~Worker() = default; std::unique_ptr Worker::parseRasterTile(std::unique_ptr bucket, const std::shared_ptr data, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::parseRasterTile, callback, bucket, data); } std::unique_ptr Worker::parseGeometryTile(TileWorker& worker, std::vector> layers, std::unique_ptr tile, PlacementConfig config, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::parseGeometryTile, callback, &worker, std::move(layers), std::move(tile), config); } std::unique_ptr Worker::parsePendingGeometryTileLayers(TileWorker& worker, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::parsePendingGeometryTileLayers, callback, &worker); } std::unique_ptr Worker::redoPlacement(TileWorker& worker, const std::unordered_map>& buckets, PlacementConfig config, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, callback, &worker, &buckets, config); } } // end namespace mbgl