#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) { std::unique_ptr image(new util::Image(*data)); if (!(*image)) { callback(RasterTileParseResult("error parsing raster image")); } if (!bucket->setImage(std::move(image))) { callback(RasterTileParseResult("error setting raster image to bucket")); } callback(RasterTileParseResult(std::move(bucket))); } void parseGeometryTile(TileWorker* worker, std::vector> layers, std::unique_ptr tile, PlacementConfig config, std::function callback) { try { callback(worker->parseAllLayers(layers, *tile, config)); } catch (const std::exception& ex) { callback(TileParseResult(ex.what())); } } void parsePendingGeometryTileLayers(TileWorker* worker, std::function callback) { try { callback(worker->parsePendingLayers()); } catch (const std::exception& ex) { callback(TileParseResult(ex.what())); } } void redoPlacement(TileWorker* worker, std::vector> layers, const std::unordered_map>* buckets, PlacementConfig config, std::function callback) { worker->redoPlacement(layers, 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, std::vector> layers, const std::unordered_map>& buckets, PlacementConfig config, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, callback, &worker, layers, &buckets, config); } } // end namespace mbgl