#include #include #include #include #include #include #include #include #include #include namespace mbgl { class Worker::Impl { public: Impl() = default; void parseRasterTile(std::unique_ptr bucket, std::shared_ptr data, std::function callback) { try { bucket->setImage(decodeImage(*data)); // Destruct the shared pointer before calling the callback. data.reset(); callback(RasterTileParseResult(std::move(bucket))); } catch (...) { callback(std::current_exception()); } } void parseGeometryTile(TileWorker* worker, std::vector> layers, std::unique_ptr tileData, PlacementConfig config, std::function callback) { try { callback(worker->parseAllLayers(std::move(layers), std::move(tileData), config)); } catch (...) { callback(std::current_exception()); } } void parsePendingGeometryTileLayers(TileWorker* worker, PlacementConfig config, std::function callback) { try { callback(worker->parsePendingLayers(config)); } catch (...) { callback(std::current_exception()); } } void redoLayout(TileWorker* worker, std::vector> layers, PlacementConfig config, std::function callback) { try { callback(worker->redoLayout(std::move(layers), config)); } catch (...) { callback(std::current_exception()); } } void redoPlacement(TileWorker* worker, PlacementConfig config, std::function callback) { callback(worker->redoPlacement(config)); } }; Worker::Worker(std::size_t count) { util::ThreadContext context = { "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, std::move(bucket), data, callback); } std::unique_ptr Worker::parseGeometryTile(TileWorker& worker, std::vector> layers, std::unique_ptr tileData, PlacementConfig config, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::parseGeometryTile, &worker, std::move(layers), std::move(tileData), config, callback); } std::unique_ptr Worker::parsePendingGeometryTileLayers(TileWorker& worker, PlacementConfig config, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::parsePendingGeometryTileLayers, &worker, config, callback); } std::unique_ptr Worker::redoLayout(TileWorker& worker, std::vector> layers, PlacementConfig config, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::redoLayout, &worker, std::move(layers), config, callback); } std::unique_ptr Worker::redoPlacement(TileWorker& worker, PlacementConfig config, std::function callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, &worker, config, callback); } } // end namespace mbgl