summaryrefslogtreecommitdiff
path: root/src/mbgl/util
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-09-06 15:01:34 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-16 12:01:06 -0700
commit41bbd4e4f7d66465433e370ca024ab0239fcace3 (patch)
tree8fe15fa31d97aafeb175a808e431b437297af88b /src/mbgl/util
parent0bd66d40ddf9e75f860fe18e7c80de9c840f48ac (diff)
downloadqtlocation-mapboxgl-41bbd4e4f7d66465433e370ca024ab0239fcace3.tar.gz
[core] Use an actor model for tile worker concurrency
Diffstat (limited to 'src/mbgl/util')
-rw-r--r--src/mbgl/util/worker.cpp129
-rw-r--r--src/mbgl/util/worker.hpp66
2 files changed, 0 insertions, 195 deletions
diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp
deleted file mode 100644
index 8245628e84..0000000000
--- a/src/mbgl/util/worker.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include <mbgl/util/worker.hpp>
-#include <mbgl/util/work_task.hpp>
-#include <mbgl/util/work_request.hpp>
-#include <mbgl/platform/platform.hpp>
-#include <mbgl/renderer/raster_bucket.hpp>
-#include <mbgl/tile/geometry_tile_data.hpp>
-#include <mbgl/style/layer.hpp>
-#include <mbgl/text/collision_tile.hpp>
-
-#include <cassert>
-#include <future>
-
-namespace mbgl {
-
-class Worker::Impl {
-public:
- Impl() = default;
-
- void parseRasterTile(std::unique_ptr<RasterBucket> bucket,
- std::shared_ptr<const std::string> data,
- std::function<void(RasterTileParseResult)> 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<std::unique_ptr<style::Layer>> layers,
- std::unique_ptr<const GeometryTileData> tileData,
- PlacementConfig config,
- std::function<void(TileParseResult)> 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<void(TileParseResult)> callback) {
- try {
- callback(worker->parsePendingLayers(config));
- } catch (...) {
- callback(std::current_exception());
- }
- }
-
- void redoLayout(TileWorker* worker,
- std::vector<std::unique_ptr<style::Layer>> layers,
- PlacementConfig config,
- std::function<void(TileParseResult)> callback) {
- try {
- callback(worker->redoLayout(std::move(layers), config));
- } catch (...) {
- callback(std::current_exception());
- }
- }
-
- void redoPlacement(TileWorker* worker,
- PlacementConfig config,
- std::function<void(TilePlacementResult)> 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<util::Thread<Impl>>(context));
- }
-}
-
-Worker::~Worker() = default;
-
-std::unique_ptr<AsyncRequest>
-Worker::parseRasterTile(std::unique_ptr<RasterBucket> bucket,
- const std::shared_ptr<const std::string> data,
- std::function<void(RasterTileParseResult)> callback) {
- current = (current + 1) % threads.size();
- return threads[current]->invokeWithCallback(&Worker::Impl::parseRasterTile, std::move(bucket),
- data, callback);
-}
-
-std::unique_ptr<AsyncRequest>
-Worker::parseGeometryTile(TileWorker& worker,
- std::vector<std::unique_ptr<style::Layer>> layers,
- std::unique_ptr<const GeometryTileData> tileData,
- PlacementConfig config,
- std::function<void(TileParseResult)> 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<AsyncRequest>
-Worker::parsePendingGeometryTileLayers(TileWorker& worker,
- PlacementConfig config,
- std::function<void(TileParseResult)> callback) {
- current = (current + 1) % threads.size();
- return threads[current]->invokeWithCallback(&Worker::Impl::parsePendingGeometryTileLayers,
- &worker, config, callback);
-}
-
-std::unique_ptr<AsyncRequest>
-Worker::redoLayout(TileWorker& worker,
- std::vector<std::unique_ptr<style::Layer>> layers,
- PlacementConfig config,
- std::function<void(TileParseResult)> callback) {
- current = (current + 1) % threads.size();
- return threads[current]->invokeWithCallback(&Worker::Impl::redoLayout, &worker,
- std::move(layers), config, callback);
-}
-
-std::unique_ptr<AsyncRequest>
-Worker::redoPlacement(TileWorker& worker,
- PlacementConfig config,
- std::function<void(TilePlacementResult)> callback) {
- current = (current + 1) % threads.size();
- return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, &worker,
- config, callback);
-}
-
-} // end namespace mbgl
diff --git a/src/mbgl/util/worker.hpp b/src/mbgl/util/worker.hpp
deleted file mode 100644
index 5b2ea06525..0000000000
--- a/src/mbgl/util/worker.hpp
+++ /dev/null
@@ -1,66 +0,0 @@
-#pragma once
-
-#include <mbgl/util/noncopyable.hpp>
-#include <mbgl/util/thread.hpp>
-#include <mbgl/tile/tile_worker.hpp>
-
-#include <functional>
-#include <memory>
-
-namespace mbgl {
-
-class AsyncRequest;
-class RasterBucket;
-class GeometryTileLoader;
-class CollisionTile;
-
-using RasterTileParseResult = variant<
- std::unique_ptr<Bucket>, // success
- std::exception_ptr>; // error
-
-class Worker : public mbgl::util::noncopyable {
-public:
- explicit Worker(std::size_t count);
- ~Worker();
-
- // Request work be done on a thread pool. Callbacks are executed on the invoking
- // thread, which must have a run loop, after the work is complete.
- //
- // The return value represents the request to perform the work asynchronously.
- // Its destructor guarantees that the work function has finished executing, and
- // that the after function has either finished executing or will not execute.
- // Together, this means that an object may make a work request with lambdas which
- // bind references to itself, and if and when those lambdas execute, the references
- // will still be valid.
-
- using Request = std::unique_ptr<AsyncRequest>;
-
- Request parseRasterTile(std::unique_ptr<RasterBucket> bucket,
- std::shared_ptr<const std::string> data,
- std::function<void(RasterTileParseResult)> callback);
-
- Request parseGeometryTile(TileWorker&,
- std::vector<std::unique_ptr<style::Layer>>,
- std::unique_ptr<const GeometryTileData>,
- PlacementConfig,
- std::function<void(TileParseResult)> callback);
-
- Request parsePendingGeometryTileLayers(TileWorker&,
- PlacementConfig config,
- std::function<void(TileParseResult)> callback);
-
- Request redoLayout(TileWorker&,
- std::vector<std::unique_ptr<style::Layer>>,
- PlacementConfig,
- std::function<void(TileParseResult)> callback);
-
- Request redoPlacement(TileWorker&,
- PlacementConfig config,
- std::function<void(TilePlacementResult)> callback);
-
-private:
- class Impl;
- std::vector<std::unique_ptr<util::Thread<Impl>>> threads;
- std::size_t current = 0;
-};
-} // namespace mbgl